"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { BarChart3, Zap, Microscope, Shield, Settings, ChevronDown, Search, type LucideIcon, } from "lucide-react"; /** * Left sidebar navigation with collapsible sections. * Chrome is intentionally dimmed (muted text) so the content area reads as primary; * the active item gets an accent tint + left bar. */ interface NavItem { label: string; href: string; } interface NavSection { title: string; icon: LucideIcon; items: NavItem[]; } const SECTIONS: NavSection[] = [ { title: "Research", icon: BarChart3, items: [ { label: "Overview", href: "/" }, { label: "Market Outlook", href: "/market-outlook" }, { label: "Institutional", href: "/institutional" }, { label: "Charts", href: "/chart-lab" }, ], }, { title: "Execution", icon: Zap, items: [ { label: "Trade Plan", href: "/trade-plan" }, { label: "Execution", href: "/execution" }, { label: "Trade Closure", href: "/trade-closure" }, { label: "Daily Focus", href: "/daily-focus" }, ], }, { title: "Analytics", icon: Microscope, items: [ { label: "Risk Posture", href: "/risk" }, { label: "Filings", href: "/filings" }, { label: "Options DD", href: "/options-dd" }, ], }, { title: "Admin", icon: Shield, items: [ { label: "Overview", href: "/admin" }, { label: "Users", href: "/admin/users" }, { label: "Queue", href: "/admin/queue" }, { label: "Audit Logs", href: "/admin/audit-logs" }, { label: "X Accounts", href: "/admin/x-accounts" }, ], }, { title: "Settings", icon: Settings, items: [{ label: "Profile / Auth", href: "/settings" }], }, ]; const STORAGE_KEY = "iflow-nav-collapsed"; function getInitialCollapsed(pathname: string): Record { if (typeof window !== "undefined") { try { const stored = localStorage.getItem(STORAGE_KEY); if (stored) return JSON.parse(stored); } catch { /* ignore */ } } const initial: Record = {}; const norm = (pathname || "/").replace(/\/+$/, "") || "/"; for (const section of SECTIONS) { const isActive = section.items.some((item) => item.href === norm); initial[section.title] = !isActive; } return initial; } export function SidebarNav() { const pathname = usePathname(); const normalizedPath = (pathname || "/").replace(/\/+$/, "") || "/"; const [collapsed, setCollapsed] = useState>({}); const [initialized, setInitialized] = useState(false); useEffect(() => { setCollapsed(getInitialCollapsed(pathname)); setInitialized(true); }, []); useEffect(() => { if (initialized) { try { localStorage.setItem(STORAGE_KEY, JSON.stringify(collapsed)); } catch { /* ignore */ } } }, [collapsed, initialized]); const toggleCollapse = (sectionTitle: string) => { setCollapsed((prev) => ({ ...prev, [sectionTitle]: !prev[sectionTitle] })); }; const openPalette = () => window.dispatchEvent(new CustomEvent("open-command-palette")); return ( ); }