'use client' import Link from 'next/link' import Image from 'next/image' import { usePathname } from 'next/navigation' import { useStore } from '@/lib/store' import { LayoutDashboard, Eye, Briefcase, Gavel, TrendingUp, Settings, ChevronLeft, ChevronRight, LogOut, Crown, Zap, Shield, CreditCard, Menu, X, Sparkles, Tag, Target, Link2, } 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) const [mobileOpen, setMobileOpen] = 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') } }, []) // Close mobile menu on route change useEffect(() => { setMobileOpen(false) }, [pathname]) // 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 // Count available domains for notification badge const availableCount = domains?.filter(d => d.is_available).length || 0 const isTycoon = tierName.toLowerCase() === 'tycoon' // SECTION 1: Discover - External market data const discoverItems = [ { href: '/command/auctions', label: 'Auctions', icon: Gavel, badge: null, }, { href: '/command/marketplace', label: 'Marketplace', icon: Tag, badge: null, }, { href: '/command/intelligence', label: 'TLD Intelligence', icon: TrendingUp, badge: null, }, ] // SECTION 2: Manage - Your own assets and tools const manageItems: Array<{ href: string label: string icon: any badge: number | null tycoonOnly?: boolean }> = [ { href: '/command/dashboard', label: 'Dashboard', icon: LayoutDashboard, badge: null, }, { href: '/command/watchlist', label: 'Watchlist', icon: Eye, badge: availableCount || null, }, { href: '/command/portfolio', label: 'Portfolio', icon: Briefcase, badge: null, }, { href: '/command/listings', label: 'My Listings', icon: Tag, badge: null, }, { href: '/command/alerts', label: 'Sniper Alerts', icon: Target, badge: null, }, { href: '/command/seo', label: 'SEO Juice', icon: Link2, badge: null, tycoonOnly: true, }, ] const bottomItems = [ { href: '/command/settings', label: 'Settings', icon: Settings }, ] const isActive = (href: string) => { if (href === '/command/dashboard') return pathname === '/command/dashboard' || pathname === '/command' return pathname.startsWith(href) } const SidebarContent = () => ( <> {/* Logo Section */}
{/* Glow effect behind logo */}
pounce
{!collapsed && (
POUNCE Command Center
)}
{/* Main Navigation */} {/* Bottom Section */}
{/* Admin Link */} {user?.is_admin && ( setMobileOpen(false)} className={clsx( "group relative flex items-center gap-3 px-3 py-3 rounded-xl transition-all duration-300", pathname.startsWith('/admin') ? "bg-gradient-to-r from-accent/20 to-accent/5 text-accent border border-accent/30" : "text-accent/70 hover:text-accent hover:bg-accent/5 border border-transparent" )} title={collapsed ? "Admin Panel" : undefined} > {pathname.startsWith('/admin') && (
)} {!collapsed && Admin Panel} )} {/* Settings */} {bottomItems.map((item) => ( setMobileOpen(false)} className={clsx( "group relative flex items-center gap-3 px-3 py-3 rounded-xl transition-all duration-300", isActive(item.href) ? "bg-foreground/10 text-foreground border border-foreground/10" : "text-foreground-muted hover:text-foreground hover:bg-foreground/5 border border-transparent" )} title={collapsed ? item.label : undefined} > {!collapsed && {item.label}} ))} {/* User Card */}
{collapsed ? (
) : ( <>

{user?.name || user?.email?.split('@')[0]}

{tierName} {tierName === 'Tycoon' && }
{/* Usage bar */}
Domains {subscription?.domains_used || 0}/{subscription?.domain_limit || 5}
{tierName === 'Scout' && ( Upgrade Plan )} )}
{/* Logout */}
{/* Collapse Toggle - Desktop only */} ) return ( <> {/* Mobile Menu Button */} {/* Mobile Overlay */} {mobileOpen && (
setMobileOpen(false)} /> )} {/* Mobile Sidebar */} {/* Desktop Sidebar */} ) }