'use client' import { useState } from 'react' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' import { createClient } from '@/lib/supabase/client' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { LayoutDashboard, Receipt, Users, ArrowLeftRight, BookOpen, BarChart3, Settings, LogOut, Calculator, Upload, Calendar, Camera, Menu, X, HelpCircle, ChevronDown, ChevronUp, Building2, } from 'lucide-react' import type { EntityType } from '@/types' interface DashboardNavProps { companyName: string entityType: EntityType } interface NavItem { href: string label: string icon: typeof LayoutDashboard group: string modes?: EntityType[] // If set, only visible for these entity types. If not set, visible to all. } // All nav items for sidebar and mobile drawer const navItems: NavItem[] = [ { href: '/', label: 'Översikt', icon: LayoutDashboard, group: 'main' }, { href: '/calendar', label: 'Kalender', icon: Calendar, group: 'main' }, { href: '/invoices', label: 'Fakturor', icon: Receipt, group: 'finans' }, { href: '/customers', label: 'Kunder', icon: Users, group: 'finans' }, { href: '/transactions', label: 'Transaktioner', icon: ArrowLeftRight, group: 'finans' }, { href: '/receipts', label: 'Kvitton', icon: Camera, group: 'finans' }, { href: '/deductions', label: 'Avdrag', icon: Calculator, group: 'finans' }, { href: '/bookkeeping', label: 'Bokföring', icon: BookOpen, group: 'finans' }, { href: '/modules', label: 'Företagsmoduler', icon: Building2, group: 'moduler' }, { href: '/import', label: 'Importera', icon: Upload, group: 'övrigt' }, { href: '/reports', label: 'Rapporter', icon: BarChart3, group: 'övrigt' }, { href: '/help', label: 'Hjälp', icon: HelpCircle, group: 'övrigt' }, { href: '/settings', label: 'Inställningar', icon: Settings, group: 'övrigt' }, ] const groupLabels: Record = { main: 'Huvudmeny', finans: 'Finans', moduler: 'Företagsmoduler', övrigt: 'Övrigt', } export default function DashboardNav({ companyName, entityType }: DashboardNavProps) { const pathname = usePathname() const router = useRouter() const supabase = createClient() const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false) const [isOvrigtExpanded, setIsOvrigtExpanded] = useState(false) const handleLogout = async () => { await supabase.auth.signOut() router.push('/login') } const isActive = (href: string) => { if (href === '/') { return pathname === '/' } return pathname.startsWith(href) } const closeMobileMenu = () => setIsMobileMenuOpen(false) // Filter nav items by entity type const filteredItems = navItems.filter(item => !item.modes || item.modes.includes(entityType) ) const mainItems = filteredItems.filter(i => i.group === 'main') const finansItems = filteredItems.filter(i => i.group === 'finans') const modulerItems = filteredItems.filter(i => i.group === 'moduler') const övrigtItems = filteredItems.filter(i => i.group === 'övrigt') const mobileNavItems = [ { href: '/', label: 'Översikt', icon: LayoutDashboard }, { href: '/invoices', label: 'Fakturor', icon: Receipt }, { href: '/receipts/scan', label: 'Skanna', icon: Camera, isScan: true }, { href: '/transactions', label: 'Transaktioner', icon: ArrowLeftRight }, ] return ( <> {/* Desktop sidebar */} {/* Mobile bottom navigation */} {/* Mobile menu drawer */} {isMobileMenuOpen && ( <> {/* Backdrop */}