import { useState, useContext } from 'react' import { NavLink } from 'react-router-dom' import { LayoutDashboard, FileEdit, Image, Calendar, Wallet, FolderKanban, CheckSquare, Users, ChevronLeft, ChevronRight, ChevronDown, Sparkles, Shield, LogOut, User, Settings, Languages, Tag, LayoutList, Receipt, BarChart3, Palette, CalendarDays, AlertCircle } from 'lucide-react' import { useAuth } from '../contexts/AuthContext' import { useLanguage } from '../i18n/LanguageContext' // Standalone items (no category) const standaloneTop = [ { to: '/', icon: LayoutDashboard, labelKey: 'nav.dashboard', end: true, tutorial: 'dashboard' }, ] // Grouped items by module const moduleGroups = [ { module: 'marketing', labelKey: 'modules.marketing', icon: Calendar, items: [ { to: '/campaigns', icon: Calendar, labelKey: 'nav.campaigns', tutorial: 'campaigns' }, { to: '/posts', icon: FileEdit, labelKey: 'nav.posts', tutorial: 'posts' }, { to: '/calendar', icon: CalendarDays, labelKey: 'nav.calendar' }, { to: '/artefacts', icon: Palette, labelKey: 'nav.artefacts' }, { to: '/assets', icon: Image, labelKey: 'nav.assets', tutorial: 'assets' }, { to: '/brands', icon: Tag, labelKey: 'nav.brands' }, ], }, { module: 'projects', labelKey: 'modules.projects', icon: FolderKanban, items: [ { to: '/projects', icon: LayoutList, labelKey: 'nav.projects' }, { to: '/tasks', icon: CheckSquare, labelKey: 'nav.tasks', tutorial: 'tasks' }, ], }, { module: 'finance', labelKey: 'modules.finance', icon: Wallet, minRole: 'manager', items: [ { to: '/finance', icon: BarChart3, labelKey: 'nav.financeDashboard' }, { to: '/budgets', icon: Receipt, labelKey: 'nav.budgets' }, ], }, { module: 'issues', labelKey: 'modules.issues', icon: AlertCircle, items: [ { to: '/issues', icon: AlertCircle, labelKey: 'nav.issues' }, ], }, ] const standaloneBottom = [ { to: '/team', icon: Users, labelKey: 'nav.team', tutorial: 'team' }, ] const ROLE_LEVEL = { contributor: 0, manager: 1, superadmin: 2 } export default function Sidebar({ collapsed, setCollapsed }) { const { user: currentUser, logout, hasModule } = useAuth() const { t, lang, setLang } = useLanguage() const userLevel = ROLE_LEVEL[currentUser?.role] ?? 0 // Track expanded state for each module group const [expandedGroups, setExpandedGroups] = useState(() => { const initial = {} moduleGroups.forEach(g => { initial[g.module] = true }) return initial }) const toggleGroup = (module) => { setExpandedGroups(prev => ({ ...prev, [module]: !prev[module] })) } const navLink = ({ to, icon: Icon, labelKey, end, tutorial }, { sub = false } = {}) => ( `flex items-center gap-3 rounded-lg font-medium transition-all duration-200 group ${ sub ? 'px-3 py-1.5 ms-5 text-[13px]' : 'px-3 py-2 text-sm' } ${ isActive ? 'bg-white/15 text-white shadow-sm sidebar-active-glow' : 'text-text-on-dark-muted hover:bg-white/8 hover:text-white' }` } > {!collapsed && {t(labelKey)}} ) const visibleGroups = moduleGroups.filter(group => { if (!hasModule(group.module)) return false if (group.minRole && userLevel < (ROLE_LEVEL[group.minRole] ?? 0)) return false return true }) return ( ) }