'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useAuthStore } from '@/stores/auth.store'; interface NavItem { label: string; href: string; icon: React.ReactNode; /** Module name for access check — if set, item only shows when user canView this module */ module?: string; /** Fallback: legacy role check (used if module not set) */ roles?: string[]; } /* SVG icons — no emojis */ const icons = { dashboard: ( ), clients: ( ), subscriptions: ( ), tickets: ( ), invoices: ( ), payments: ( ), areas: ( ), plans: ( ), users: ( ), settings: ( ), }; const NAV_ITEMS: NavItem[] = [ { label: 'Dashboard', href: '/dashboard', icon: icons.dashboard, module: 'dashboard' }, { label: 'Clients', href: '/dashboard/clients', icon: icons.clients, module: 'clients' }, { label: 'Tickets', href: '/dashboard/tickets', icon: icons.tickets, module: 'tickets' }, { label: 'Invoices', href: '/dashboard/invoices', icon: icons.invoices, module: 'invoices' }, { label: 'Payments', href: '/dashboard/payments', icon: icons.payments, module: 'payments' }, { label: 'Employees', href: '/dashboard/employees', icon: icons.users, module: 'employees' }, { label: 'Payroll', href: '/dashboard/payroll', icon: icons.payments, module: 'payroll' }, { label: 'Expenses', href: '/dashboard/expenses', icon: icons.payments, module: 'expenses' }, { label: 'Assets', href: '/dashboard/assets', icon: icons.plans, module: 'assets' }, { label: 'Fund Transfers', href: '/dashboard/accounts', icon: icons.invoices, module: 'fund_transfers' }, { label: 'Accounting', href: '/dashboard/accounting', icon: icons.subscriptions, module: 'accounting' }, { label: 'Reports', href: '/dashboard/reports', icon: icons.invoices, module: 'reports' }, { label: 'Settings', href: '/dashboard/settings', icon: icons.settings, module: 'settings' }, ]; export function Sidebar() { const pathname = usePathname(); const user = useAuthStore((s) => s.user); const canView = useAuthStore((s) => s.canView); const isSuperAdmin = useAuthStore((s) => s.isSuperAdmin); const visibleItems = NAV_ITEMS.filter((item) => { // Super admin sees everything if (isSuperAdmin()) return true; // Check module-level access if (item.module) return canView(item.module); return true; }); return ( ); }