'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,
Gavel,
TrendingUp,
Settings,
ChevronLeft,
ChevronRight,
LogOut,
Crown,
Zap,
Shield,
CreditCard,
Menu,
X,
Sparkles,
Tag,
Briefcase,
} 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
// 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: '/terminal/market',
label: 'MARKET',
icon: Gavel,
badge: null,
},
{
href: '/terminal/intel',
label: 'INTEL',
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: '/terminal/radar',
label: 'RADAR',
icon: LayoutDashboard,
badge: null,
},
{
href: '/terminal/watchlist',
label: 'WATCHLIST',
icon: Eye,
badge: availableCount || null,
},
{
href: '/terminal/listing',
label: 'FOR SALE',
icon: Tag,
badge: null,
},
]
const bottomItems = [
{ href: '/terminal/settings', label: 'Settings', icon: Settings },
]
const isActive = (href: string) => {
if (href === '/terminal/radar') return pathname === '/terminal/radar' || pathname === '/terminal' || pathname === '/terminal/dashboard'
return pathname.startsWith(href)
}
const SidebarContent = () => (
<>
{/* Logo Section */}
{/* Glow effect behind logo - Reduced intensity for cleanliness */}
{!collapsed && (
POUNCE
Terminal
)}
{/* Main Navigation */}
{/* Bottom Section */}
{/* Admin Link */}
{user?.is_admin && (
setMobileOpen(false)}
className="group flex items-center gap-3 px-3 py-2.5 rounded-lg text-amber-500/80 hover:text-amber-400 hover:bg-amber-500/10 transition-all"
title={collapsed ? "Admin Panel" : undefined}
>
{!collapsed &&
Admin}
)}
{/* Settings */}
{bottomItems.map((item) => (
setMobileOpen(false)}
className={clsx(
"group flex items-center gap-3 px-3 py-2.5 rounded-lg transition-all",
isActive(item.href)
? "text-emerald-400 bg-emerald-500/[0.08]"
: "text-zinc-400 hover:text-zinc-200 hover:bg-white/[0.03]"
)}
title={collapsed ? item.label : undefined}
>
{!collapsed &&
{item.label}}
))}
{/* User Card */}
{collapsed ? (
) : (
<>
{user?.name || user?.email?.split('@')[0]}
{tierName}
{tierName === 'Tycoon' && }
{/* Usage bar */}
Usage
{subscription?.domains_used || 0}/{subscription?.domain_limit || 5}
{tierName === 'Scout' && (
Upgrade
)}
>
)}
{/* Logout */}
{/* Collapse Toggle - Desktop only */}
>
)
return (
<>
{/* Mobile Menu Button */}
{/* Mobile Overlay */}
{mobileOpen && (
setMobileOpen(false)}
/>
)}
{/* Mobile Sidebar */}
{/* Desktop Sidebar */}
>
)
}