"use client"; import React, { useState, useEffect } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { LayoutDashboard, Users, GraduationCap, BookOpen, Building2, ScanSearch, ScrollText, Radio, ClipboardCheck, BarChart3, Shield, Sliders, ChevronDown, ChevronRight, FileText, Smartphone } from "lucide-react"; import { useAuthStore } from "@/store/authStore"; import api from "@/lib/api"; interface NavItem { label: string; href: string; icon: React.ReactNode; } const adminLinks: NavItem[] = [ { label: "Overview", href: "/admin/dashboard", icon: }, { label: "Students", href: "/admin/users/students", icon: }, { label: "Teachers", href: "/admin/users/teachers", icon: }, { label: "Classes", href: "/admin/classes", icon: }, { label: "AI Scanner", href: "/admin/scanner", icon: }, { label: "Audit Log", href: "/admin/audit", icon: }, ]; const setupLinks: NavItem[] = [ { label: "Departments", href: "/admin/setup/departments", icon: }, { label: "Subjects", href: "/admin/setup/subjects", icon: }, { label: "Classrooms", href: "/admin/setup/classrooms", icon: }, { label: "Designations", href: "/admin/setup/designations", icon: }, { label: "Verification Settings", href: "/admin/setup/verification-settings", icon: }, ]; const teacherLinks: NavItem[] = [ { label: "Overview", href: "/teacher/dashboard", icon: }, { label: "My Classes", href: "/teacher/classes", icon: }, { label: "Sessions", href: "/teacher/sessions", icon: }, { label: "Review Queue", href: "/teacher/review", icon: }, { label: "Leave Requests", href: "/teacher/leaves", icon: }, { label: "Device Changes", href: "/teacher/device-changes", icon: }, ]; const teacherReportLinks: NavItem[] = [ { label: "Class Analytics", href: "/teacher/analytics", icon: }, { label: "Attendance History", href: "/teacher/history", icon: }, ]; interface SidebarProps { isOpen: boolean; onClose: () => void; } export default function Sidebar({ isOpen, onClose }: SidebarProps): React.ReactElement { const pathname = usePathname(); const user = useAuthStore((s) => s.user); const role = user?.role; const isSetupActive = pathname.startsWith("/admin/setup"); const [setupOpen, setSetupOpen] = useState(isSetupActive); const [prevIsSetupActive, setPrevIsSetupActive] = useState(isSetupActive); const [flaggedCount, setFlaggedCount] = useState(0); if (isSetupActive !== prevIsSetupActive) { setPrevIsSetupActive(isSetupActive); if (isSetupActive) { setSetupOpen(true); } } useEffect(() => { if (role !== "TEACHER") return; let isMounted = true; async function fetchFlagged(): Promise { try { const { data } = await api.get("/teacher/attendance/flagged"); if (isMounted) { setFlaggedCount(Array.isArray(data) ? data.length : 0); } } catch { // Ignore errors in background polling } } void fetchFlagged(); const interval = setInterval(() => { void fetchFlagged(); }, 60_000); return () => { isMounted = false; clearInterval(interval); }; }, [role]); return ( <> {isOpen && (
)} ); }