import { useCallback } from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { useCourses, useStudents } from "@/hooks/queries"; import { Download } from "lucide-react"; import { BarChart, Bar, PieChart, Pie, Cell, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, Legend } from "recharts"; import AiReportNarrative from "@/components/ai/AiReportNarrative"; export default function AdminReports() { const { data: coursesData, isLoading: lc } = useCourses(); const { data: studentsData, isLoading: ls } = useStudents({ size: 500 }); const courses = coursesData?.items ?? []; const students = studentsData?.items ?? []; const enrollmentByCourse = courses.map(c => ({ name: c.title.length > 12 ? c.title.slice(0, 12) + "…" : c.title, enrolled: c.enrolled ?? 0, capacity: c.max_capacity ?? 0, })); const capacityByCourse = courses.filter(c => c.status === "active").map(c => { const pct = c.max_capacity ? Math.round((c.enrolled / c.max_capacity) * 100) : 0; return { name: c.title.length > 12 ? c.title.slice(0, 12) + "…" : c.title, fillRate: pct }; }); const statusPie = [ { name: "Active", value: students.filter((s) => s.status === "active").length, color: "hsl(142, 71%, 45%)" }, { name: "Inactive", value: students.filter((s) => s.status !== "active").length, color: "hsl(38, 92%, 50%)" }, ].filter(d => d.value > 0); const enrollmentReportData = { series: enrollmentByCourse, studentCount: students.length, courseCount: courses.length }; const performanceReportData = { byCourse: capacityByCourse }; const riskReportData = { distribution: statusPie, studentCount: students.length }; const attendanceReportData = { note: "No attendance data recorded yet." }; const exportCsv = useCallback(() => { const rows = [ ["Type", "Label", "Enrolled", "Capacity"], ...enrollmentByCourse.map(r => ["Enrollment", r.name, String(r.enrolled), String(r.capacity)]), ...capacityByCourse.map(r => ["Fill Rate", r.name, String(r.fillRate) + "%", ""]), ...statusPie.map(r => ["Status", r.name, String(r.value), ""]), ]; const csv = rows.map(r => r.join(",")).join("\n"); const blob = new Blob([csv], { type: "text/csv" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = "encoach-report.csv"; a.click(); URL.revokeObjectURL(url); }, [enrollmentByCourse, capacityByCourse, statusPie]); if (lc || ls) return
Analytics and reporting dashboard.
No courses available.
}No active courses.
}No students available.
}No attendance data recorded yet. Attendance tracking will appear here once sessions are recorded.