import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Users, BookOpen, GraduationCap, Layers, Ticket, DollarSign, Plus, BarChart3, FolderOpen } from "lucide-react"; import { Link } from "react-router-dom"; import { useCourses, useBatches, useStudents, useTeachers } from "@/hooks/queries"; import { useQuery } from "@tanstack/react-query"; import { api } from "@/lib/api-client"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from "recharts"; import AiInsightsPanel from "@/components/ai/AiInsightsPanel"; import AiTipBanner from "@/components/ai/AiTipBanner"; interface DashboardStats { total_students?: number; total_teachers?: number; total_courses?: number; active_courses?: number; total_batches?: number; active_batches?: number; total_entities?: number; total_departments?: number; total_classrooms?: number; total_exams?: number; total_assignments?: number; total_tickets?: number; open_tickets?: number; total_subjects?: number; total_resources?: number; total_revenue?: number; total_payments?: number; total_exam_sessions?: number; } export default function AdminLmsDashboard() { const { data: coursesData, isLoading: lc } = useCourses(); const { data: studentsData, isLoading: ls } = useStudents({ size: 500 }); const { data: teachersData, isLoading: lt } = useTeachers({ size: 500 }); const { data: batchesData, isLoading: lb } = useBatches(); const { data: dbStats } = useQuery({ queryKey: ["dashboard", "stats"], queryFn: async () => { const res = await api.get<{ data: DashboardStats }>("/stats"); return (res as { data: DashboardStats }).data ?? res; }, staleTime: 30_000, }); const courses = coursesData?.items ?? []; const students = studentsData?.items ?? []; const teachers = teachersData?.items ?? []; const batches = batchesData?.items ?? []; if (lc || ls || lt || lb) return
; const revenue = dbStats?.total_revenue ?? 0; const openTickets = dbStats?.open_tickets ?? 0; const statCards = [ { label: "Total Students", value: String(students.length), icon: Users, color: "text-primary" }, { label: "Active Courses", value: `${courses.filter(c => c.status === "active").length} / ${courses.length}`, icon: BookOpen, color: "text-info" }, { label: "Teachers", value: String(teachers.length), icon: GraduationCap, color: "text-success" }, { label: "Active Batches", value: `${batches.filter(b => b.status === "active").length} / ${batches.length}`, icon: Layers, color: "text-warning" }, { label: "Open Tickets", value: String(openTickets), icon: Ticket, color: "text-destructive" }, { label: "Revenue", value: `$${revenue.toLocaleString()}`, icon: DollarSign, color: "text-success" }, ]; const courseChartData = courses.map(c => { const label = c.title || ""; const short = label.length > 14 ? label.substring(0, 14) + "…" : label; return { course: short, capacity: c.max_capacity ?? 0, enrolled: c.enrolled ?? 0 }; }); const batchChartData = batches.map(b => { const label = b.name || ""; const short = label.length > 12 ? label.substring(0, 12) + "…" : label; return { batch: short, capacity: b.capacity ?? 0 }; }); return (

Admin Dashboard

Platform overview and key metrics.

{statCards.map(s => (

{s.value}

{s.label}

))}
{[ { label: "Departments", value: dbStats?.total_departments ?? 0, icon: FolderOpen }, { label: "Classrooms", value: dbStats?.total_classrooms ?? 0, icon: BarChart3 }, { label: "Subjects", value: dbStats?.total_subjects ?? 0, icon: BookOpen }, { label: "Resources", value: dbStats?.total_resources ?? 0, icon: Layers }, ].map(s => (

{s.value}

{s.label}

))}
Courses Overview {courseChartData.length > 0 ? ( ) : (

No course data available.

)}
Batch Capacity {batchChartData.length > 0 ? ( ) : (

No batch data available.

)}
Quick Summary ModuleCountStatus Exams {dbStats?.total_exams ?? 0} {dbStats?.total_exam_sessions ?? 0} sessions Assignments {dbStats?.total_assignments ?? 0} across courses Support Tickets {dbStats?.total_tickets ?? 0} {openTickets} open Payments {dbStats?.total_payments ?? 0} ${revenue.toLocaleString()} total
); }