"use client"; import { useMemo, useState } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { ChevronDown, Moon, Sun, ChevronRight, Plus, Lock } from "lucide-react"; import { cn } from "@/lib/utils"; import { useColorMode } from "@/components/providers/ColorModeProvider"; import { Button } from "@/components/ds"; import { ACCOUNTING_NAV, ACCOUNTING_QUICK_BAR } from "@/lib/accounting-nav"; function isActive(pathname: string, href: string) { const base = href.split("?")[0]; if (base === "/accounting") return pathname === "/accounting"; return pathname === base || pathname.startsWith(`${base}/`); } function NavLink({ href, className, children, }: { href: string; className?: string; children: React.ReactNode; }) { const router = useRouter(); return ( { try { router.prefetch(href); } catch { /* ignore */ } }} > {children} ); } export function AccountingShell({ children }: { children: React.ReactNode }) { const pathname = usePathname(); const { mode, toggle } = useColorMode(); const [openGroups, setOpenGroups] = useState>({}); const autoOpen = useMemo(() => { const map: Record = {}; for (const g of ACCOUNTING_NAV) { if (g.href && isActive(pathname, g.href)) map[g.id] = true; if (g.items?.some((i) => isActive(pathname, i.href))) map[g.id] = true; } return map; }, [pathname]); const expanded = { ...autoOpen, ...openGroups }; const toggleGroup = (id: string) => setOpenGroups((prev) => ({ ...prev, [id]: !(expanded[id] ?? false) })); return (
{ACCOUNTING_NAV.flatMap((g) => g.href ? [{ href: g.href, label: g.label }] : (g.items ?? []).slice(0, 1).map((i) => ({ href: i.href, label: g.label })) ).map((item) => ( {item.label} ))}
{children}
{ACCOUNTING_QUICK_BAR.map((item) => ( {item.label} ))}
); }