'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, Upload, Calendar, Menu, X, HelpCircle, ChevronDown, Building2, FileInput, Wallet, } from 'lucide-react' import type { EntityType } from '@/types' interface DashboardNavProps { companyName: string entityType: EntityType uncategorizedTransactionCount?: number } 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. hidden?: boolean // Temporarily hide from sidebar } // All nav items for sidebar and mobile drawer const navItems: NavItem[] = [ { href: '/', label: 'Översikt', icon: LayoutDashboard, group: 'main' }, { href: '/deadlines', label: 'Deadlines', icon: Calendar, group: 'main' }, { href: '/invoices', label: 'Fakturor', icon: Receipt, group: 'finans' }, { href: '/customers', label: 'Kunder', icon: Users, group: 'finans' }, { href: '/expenses', label: 'Utgifter', icon: Wallet, group: 'finans' }, // Temporarily hidden pending module rework (see feedback #49) { href: '/suppliers', label: 'Leverantörer', icon: Building2, group: 'finans', hidden: true }, { href: '/supplier-invoices', label: 'Leverantörsfakturor', icon: FileInput, group: 'finans', hidden: true }, { href: '/transactions', label: 'Transaktioner', icon: ArrowLeftRight, group: 'finans' }, { href: '/bookkeeping', label: 'Bokföring', icon: BookOpen, group: 'finans' }, { href: '/reports', label: 'Rapporter', icon: BarChart3, group: 'finans' }, { href: '/import', label: 'Importera', icon: Upload, group: 'finans' }, { 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', övrigt: 'Övrigt', } export default function DashboardNav({ companyName, entityType, uncategorizedTransactionCount = 0 }: DashboardNavProps) { const pathname = usePathname() const router = useRouter() const supabase = createClient() const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false) // Auto-expand Övrigt when the user is on one of its pages, or when manually toggled const isOnOvrigtPage = ['/help', '/settings'].some(p => pathname.startsWith(p)) const [manualOvrigtExpanded, setManualOvrigtExpanded] = useState(false) const isOvrigtExpanded = isOnOvrigtPage || manualOvrigtExpanded const openMobileMenu = () => { setIsMobileMenuOpen(true) } 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 and hidden flag const filteredItems = navItems.filter(item => !item.hidden && (!item.modes || item.modes.includes(entityType)) ) const mainItems = filteredItems.filter(i => i.group === 'main') const finansItems = filteredItems.filter(i => i.group === 'finans') const övrigtItems = filteredItems.filter(i => i.group === 'övrigt') const mobileNavItems = [ { href: '/', label: 'Översikt', icon: LayoutDashboard }, { href: '/invoices', label: 'Fakturor', icon: Receipt }, { href: '/transactions', label: 'Transaktioner', icon: ArrowLeftRight }, ] return ( <> {/* Desktop sidebar */} {/* Mobile bottom navigation */} {/* Mobile menu drawer */} {isMobileMenuOpen && ( <> {/* Backdrop */}