'use client' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' import { createBrowserClient } from '@supabase/ssr' 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: }, ], } 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 } function NavLink({ item, pathname }: { item: NavItem; pathname: string }) { // Exact match for root-level single-page roles, prefix match otherwise const exactRoots = ['/reporter', '/supervisor', '/management', '/capa-owner', '/admin', '/report', '/account'] const isActive = exactRoots.includes(item.href) ? pathname === item.href : pathname.startsWith(item.href) 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 () => { const supabase = createBrowserClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, ) await supabase.auth.signOut() router.push('/login') } const displayName = userName || userEmail || 'User' const roleLabel = role.replace(/_/g, ' ').replace(/\b\w/g, c => c.toUpperCase()) return ( <> {/* Desktop sidebar */} {/* Mobile bottom tab bar */} ) }