import { useLocation, Link, useNavigate } from 'react-router'; import { useTranslation } from 'react-i18next'; import { LayoutDashboard, ArrowLeftRight, BarChart3, Store, ScrollText, Settings, LogOut, Wallet, Mail, } from 'lucide-react'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { cn } from '@/lib/utils'; import { useAuthStore } from '@/stores/authStore'; interface NavItem { icon: React.ElementType; labelKey: string; href: string; } const navItems: NavItem[] = [ { icon: LayoutDashboard, labelKey: 'nav.dashboard', href: '/dashboard' }, { icon: ArrowLeftRight, labelKey: 'nav.transactions', href: '/transactions' }, { icon: BarChart3, labelKey: 'nav.reports', href: '/reports' }, { icon: Store, labelKey: 'nav.branches', href: '/branches' }, { icon: ScrollText, labelKey: 'nav.journal', href: '/journal' }, { icon: Mail, labelKey: 'nav.emailSenders', href: '/email-senders' }, { icon: Settings, labelKey: 'nav.settings', href: '/settings' }, ]; function getInitials(name?: string | null): string { if (!name) return '?'; const parts = name.trim().split(/\s+/); if (parts.length >= 2) return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase(); return name.slice(0, 2).toUpperCase(); } function getDisplayName(name?: string | null): string { if (!name) return 'Utilisateur'; const parts = name.trim().split(/\s+/); if (parts.length >= 2) return `${parts[0]} ${parts[parts.length - 1][0]}.`; return name; } const ROLE_LABELS: Record = { admin: 'Administrateur', editor: 'Éditeur', viewer: 'Lecteur', }; export default function Sidebar() { const { t } = useTranslation(); const location = useLocation(); const navigate = useNavigate(); const user = useAuthStore((s) => s.user); const handleLogout = async () => { try { await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' }); } catch { // Ignore errors — clear cookies and redirect regardless } useAuthStore.getState().logout(); navigate('/login'); }; return ( ); }