import { BarChart3, Bell, BookOpen, ChevronLeft, ChevronRight, CircleAlert, ClipboardList, LayoutDashboard, LogOut, Shield, UserCircle2, Users, Users2, Settings, X, } from "lucide-react"; import { type ComponentType, useEffect, useState } from "react"; import { NavLink } from "react-router-dom"; import { cn } from "../../lib/utils"; import { BrandLogo } from "../brand/BrandLogo"; import { getUnreadCount } from "../../api/notifications.api"; import { SidebarNavGroup } from "./SidebarNavGroup"; type NavLinkItem = { kind: "link"; label: string; to: string; icon: ComponentType<{ className?: string }>; }; type NavGroupItem = { kind: "group"; label: string; basePath: string; icon: ComponentType<{ className?: string }>; children: { label: string; to: string; end?: boolean }[]; }; type NavEntry = NavLinkItem | NavGroupItem; const navEntries: NavEntry[] = [ { kind: "link", label: "Dashboard", to: "/dashboard", icon: LayoutDashboard }, { kind: "link", label: "User Management", to: "/users", icon: Users }, { kind: "link", label: "Role Management", to: "/roles", icon: Shield }, { kind: "link", label: "Content Management", to: "/content", icon: BookOpen }, { kind: "link", label: "New Content", to: "/new-content", icon: BookOpen }, { kind: "group", label: "Notifications", basePath: "/notifications", icon: Bell, children: [ { label: "My Notifications", to: "/notifications", end: true }, { label: "Email Templates", to: "/notifications/email-templates" }, ], }, { kind: "link", label: "User Log", to: "/user-log", icon: ClipboardList }, { kind: "link", label: "Issue Reports", to: "/issues", icon: CircleAlert }, { kind: "link", label: "Analytics", to: "/analytics", icon: BarChart3 }, { kind: "link", label: "Team Management", to: "/team", icon: Users2 }, { kind: "link", label: "Profile", to: "/profile", icon: UserCircle2 }, { kind: "link", label: "Settings", to: "/settings", icon: Settings }, ]; type SidebarProps = { isOpen: boolean; isCollapsed: boolean; onToggleCollapse: () => void; onClose: () => void; }; export function Sidebar({ isOpen, isCollapsed, onToggleCollapse, onClose, }: SidebarProps) { const [unreadCount, setUnreadCount] = useState(0); useEffect(() => { const fetchUnread = async () => { try { const res = await getUnreadCount(); setUnreadCount(res.data.unread); } catch { // silently fail } }; fetchUnread(); window.addEventListener("notifications-updated", fetchUnread); return () => window.removeEventListener("notifications-updated", fetchUnread); }, []); const unreadBadge = unreadCount > 0 && ( {unreadCount > 99 ? "99+" : unreadCount} ); const collapsedUnreadDot = unreadCount > 0 && ( ); return ( <>