'use client'; import { useState } from 'react'; import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; import { LayoutDashboard, Users, CreditCard, Key, KeyRound, BarChart3, Settings, Package, LogOut, Menu, X, ScrollText, Sun, Moon, Ticket, Tag, Gift, Palette, Wallet, Bell, BookOpen, Activity, FileText, Shield, MessageSquare, Megaphone, ClipboardList, Workflow, Beaker, Crosshair, Bug, HeartPulse, FileSearch, FlaskConical, BrainCircuit, TrendingDown, Building2, LifeBuoy, Coins, ListOrdered, Webhook, Database, Star, Store, Mail, Timer, Radio, ShieldBan, Wrench, MonitorSmartphone, Bot, Globe, Download, } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useAuth } from '@/lib/auth-context'; import { useTheme } from '@/lib/theme-context'; import { ProductSwitcher } from '@/components/product-switcher'; const navItems = [ { href: '/', label: 'Dashboard', icon: LayoutDashboard }, { href: '/users', label: 'Users', icon: Users }, { href: '/subscriptions', label: 'Subscriptions', icon: CreditCard }, { href: '/licenses', label: 'Licenses', icon: KeyRound }, { href: '/tokens', label: 'API Tokens', icon: Key }, { href: '/usage', label: 'Usage Analytics', icon: BarChart3 }, { href: '/invitations', label: 'Invitations', icon: Ticket }, { href: '/promos', label: 'Promo Codes', icon: Tag }, { href: '/referrals', label: 'Referrals', icon: Gift }, { href: '/broadcasts', label: 'Broadcasts', icon: Megaphone }, { href: '/surveys', label: 'Surveys', icon: ClipboardList }, { href: '/themes', label: 'Themes', icon: Palette }, { href: '/billing', label: 'Billing', icon: Wallet }, { href: '/products', label: 'Products', icon: Package }, { href: '/notifications', label: 'Notifications', icon: Bell }, { href: '/docs', label: 'Docs & Runbooks', icon: BookOpen }, { href: '/flags', label: 'Feature Flags', icon: Settings }, { href: '/audit', label: 'Audit Log', icon: ScrollText }, { href: '/actiontrail', label: 'ActionTrail', icon: Crosshair }, { href: '/timeline', label: 'Timeline', icon: Workflow }, { href: '/organizations', label: 'Organizations', icon: Building2 }, { href: '/support', label: 'Support Cases', icon: LifeBuoy }, { href: '/ai-budgets', label: 'AI Budgets', icon: Coins }, { href: '/waitlist', label: 'Waitlist', icon: ListOrdered }, { href: '/webhooks', label: 'Webhooks', icon: Webhook }, { href: '/knowledge', label: 'Knowledge Bases', icon: Database }, { href: '/agent-evals', label: 'Agent Evals', icon: FlaskConical }, { href: '/reviews', label: 'Reviews', icon: Star }, { href: '/marketplace', label: 'Marketplace', icon: Store }, { href: '/delivery', label: 'Delivery Log', icon: Mail }, { href: '/jobs', label: 'Scheduled Jobs', icon: Timer }, { href: '/agent-runtime', label: 'Agent Runtime', icon: Bot }, { href: '/event-subscriptions', label: 'Event Subs', icon: Radio }, { href: '/ip-rules', label: 'IP Rules', icon: ShieldBan }, { href: '/maintenance', label: 'Maintenance', icon: Wrench }, { href: '/sessions-admin', label: 'Sessions', icon: MonitorSmartphone }, { href: '/status', label: 'Status', icon: Globe }, { href: '/gdpr-export', label: 'GDPR Export', icon: Download }, { href: '/experiments', label: 'Experiments', icon: FlaskConical }, { href: '/predictive/at-risk', label: 'Predictive', icon: TrendingDown }, { href: '/ops', label: 'Mission Control', icon: Activity }, { href: '/ops/client-logs', label: 'Client Logs', icon: FileText }, { href: '/ops/telemetry-policies', label: 'Telemetry Policies', icon: Shield }, { href: '/ops/ab-testing', label: 'A/B Testing', icon: Beaker }, { href: '/debug-sessions', label: 'Debug Sessions', icon: Bug }, { href: '/health-dashboard', label: 'Health Dashboard', icon: HeartPulse }, { href: '/extraction', label: 'Extraction', icon: FileSearch }, { href: '/ai-diagnostics', label: 'AI Diagnostics', icon: BrainCircuit }, { href: '/feedback', label: 'User Feedback', icon: MessageSquare }, { href: '/ops/secrets', label: 'Secrets Manager', icon: KeyRound }, { href: '/settings', label: 'Settings', icon: Settings }, ]; export function SidebarNav() { const pathname = usePathname(); const router = useRouter(); const { user, logout } = useAuth(); const { resolved, setTheme } = useTheme(); const [mobileOpen, setMobileOpen] = useState(false); const handleLogout = () => { logout(); router.replace('/login'); }; const initials = user?.name ? user.name .split(' ') .map(w => w[0]) .join('') .toUpperCase() .slice(0, 2) : '??'; const sidebarContent = ( <> {/* Logo */}

Admin

Admin Console

{/* Mobile close button */}
{/* Product Switcher */} {/* Navigation */} {/* Footer — theme toggle + user info + logout */}
{initials}

{user?.name ?? 'Admin'}

{user?.email ?? ''}

); return ( <> {/* Mobile hamburger */}
Platform Admin
{/* Spacer for mobile top bar */}
{/* Overlay */} {mobileOpen && (
setMobileOpen(false)} /> )} {/* Sidebar — always visible on md+, slide-in on mobile */} ); }