'use client' import Link from 'next/link' import { usePathname } from 'next/navigation' import { useStore } from '@/lib/store' import { LayoutDashboard, Eye, Briefcase, Gavel, TrendingUp, Settings, ChevronLeft, ChevronRight, LogOut, Crown, Zap, Shield, CreditCard, } from 'lucide-react' import { useState, useEffect } from 'react' import clsx from 'clsx' interface SidebarProps { collapsed?: boolean onCollapsedChange?: (collapsed: boolean) => void } export function Sidebar({ collapsed: controlledCollapsed, onCollapsedChange }: SidebarProps) { const pathname = usePathname() const { user, logout, subscription, domains } = useStore() // Internal state for uncontrolled mode const [internalCollapsed, setInternalCollapsed] = useState(false) // Use controlled or uncontrolled state const collapsed = controlledCollapsed ?? internalCollapsed const setCollapsed = onCollapsedChange ?? setInternalCollapsed // Load collapsed state from localStorage useEffect(() => { const saved = localStorage.getItem('sidebar-collapsed') if (saved) { setCollapsed(saved === 'true') } }, []) // Save collapsed state const toggleCollapsed = () => { const newState = !collapsed setCollapsed(newState) localStorage.setItem('sidebar-collapsed', String(newState)) } const tierName = subscription?.tier_name || subscription?.tier || 'Scout' const tierIcon = tierName === 'Tycoon' ? Crown : tierName === 'Trader' ? TrendingUp : Zap const TierIcon = tierIcon // Navigation items const navItems = [ { href: '/dashboard', label: 'Dashboard', icon: LayoutDashboard, badge: null, }, { href: '/watchlist', label: 'Watchlist', icon: Eye, badge: domains?.filter(d => d.is_available).length || null, }, { href: '/portfolio', label: 'Portfolio', icon: Briefcase, badge: null, }, { href: '/market', label: 'Market', icon: Gavel, badge: null, }, { href: '/intelligence', label: 'Intelligence', icon: TrendingUp, badge: null, }, ] const bottomItems = [ { href: '/settings', label: 'Settings', icon: Settings }, ] const isActive = (href: string) => { if (href === '/dashboard') return pathname === '/dashboard' return pathname.startsWith(href) } return ( ) }