'use client' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' import { AlignLeft, CircleCheck, ClipboardList, LayoutDashboard, LogOut, Plus, Settings, User, Users, } from 'lucide-react' import { NotificationBell } from '@/components/notifications/bell' interface NavItem { label: string href: string icon: React.ReactNode } interface SidebarProps { role: string userName: string userEmail: string } const IconGrid = () => const IconList = () => const IconCheck = () => const IconChart = () => const IconSettings = () => const IconUsers = () => const IconPlus = () => const IconLogout = () => const IconUser = () => const NAV_ITEMS: Record = { reporter: [ { label: 'My Reports', href: '/reporter', icon: }, { label: 'New Incident', href: '/report', icon: }, ], supervisor: [ { label: 'Overview', href: '/supervisor', icon: }, { label: 'Incidents', href: '/supervisor/incidents', icon: }, ], hse: [ { label: 'Dashboard', href: '/hse/dashboard', icon: }, { label: 'Incidents', href: '/hse/incidents', icon: }, { label: 'CAPA', href: '/hse/capa', icon: }, { label: 'Settings', href: '/hse/settings', icon: }, ], management: [ { label: 'Dashboard', href: '/management', icon: }, ], capa_owner: [ { label: 'My CAPAs', href: '/capa-owner', icon: }, ], admin: [ { label: 'Admin', href: '/admin', icon: }, { label: 'Dashboard', href: '/hse/dashboard', icon: }, { label: 'Incidents', href: '/hse/incidents', icon: }, { label: 'CAPA', href: '/hse/capa', icon: }, { label: 'Management', href: '/management', icon: }, { label: 'Settings', href: '/hse/settings', icon: }, ], } const EXACT_ROOTS = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account'] function isActivePath(href: string, pathname: string): boolean { return EXACT_ROOTS.includes(href) ? pathname === href : pathname.startsWith(href) } function initials(name: string): string { return name .split(' ') .map(w => w[0] ?? '') .join('') .toUpperCase() .slice(0, 2) } function useNavItems(role: string): NavItem[] { return NAV_ITEMS[role] ?? NAV_ITEMS.reporter } const LINK_BASE = 'flex items-center gap-3 px-3 py-2 text-sm border-l-2 transition-colors' const LINK_ACTIVE = 'border-accent text-accent-700 font-extrabold bg-accent-100/50' const LINK_IDLE = 'border-transparent text-ink/70 font-medium hover:bg-ink/7 hover:text-ink' function NavLink({ item, pathname }: { item: NavItem; pathname: string }) { const active = isActivePath(item.href, pathname) return ( {item.icon} {item.label} ) } export function Sidebar({ role, userName, userEmail }: SidebarProps) { const pathname = usePathname() const router = useRouter() const items = useNavItems(role) const mobileItems = items.slice(0, 4) const logout = async () => { await fetch('/api/auth/logout', { method: 'POST' }) router.push('/login') router.refresh() } const displayName = userName || userEmail || 'User' const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) const accountActive = pathname === '/account' return ( <> {/* Desktop sidebar */} {/* Mobile bottom tab bar */} ) }