'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useAuth } from '@/lib/auth'; import { cn } from '@/lib/utils'; import { LayoutDashboard, Users, FileText, Shield, ShieldCheck, Scale, Flag, Settings, Activity, LogOut, ChevronLeft, ChevronRight, ChevronDown, Sliders, FolderTree, HardDrive, AtSign, Brain, ScrollText, Wrench, Bot, UserCog, ShieldAlert, Cog, } from 'lucide-react'; import { useState } from 'react'; type NavItem = { href: string; label: string; icon: any }; type NavGroup = { label: string; icon: any; items: NavItem[] }; type NavEntry = NavItem | NavGroup; function isGroup(entry: NavEntry): entry is NavGroup { return 'items' in entry; } const navigation: NavEntry[] = [ { href: '/', label: 'Dashboard', icon: LayoutDashboard }, { label: 'Users & Content', icon: UserCog, items: [ { href: '/users', label: 'Users', icon: Users }, { href: '/posts', label: 'Posts', icon: FileText }, { href: '/categories', label: 'Categories', icon: FolderTree }, { href: '/official-accounts', label: 'Official Accounts', icon: Bot }, ], }, { label: 'Moderation & Safety', icon: ShieldAlert, items: [ { href: '/moderation', label: 'Moderation Queue', icon: Shield }, { href: '/ai-moderation', label: 'AI Moderation', icon: Brain }, { href: '/ai-audit-log', label: 'AI Audit Log', icon: ScrollText }, { href: '/appeals', label: 'Appeals', icon: Scale }, { href: '/reports', label: 'Reports', icon: Flag }, { href: '/safe-links', label: 'Safe Links', icon: ShieldCheck }, { href: '/content-tools', label: 'Content Tools', icon: Wrench }, ], }, { label: 'Platform', icon: Cog, items: [ { href: '/algorithm', label: 'Algorithm', icon: Sliders }, { href: '/usernames', label: 'Usernames', icon: AtSign }, { href: '/storage', label: 'Storage', icon: HardDrive }, { href: '/system', label: 'System Health', icon: Activity }, { href: '/settings', label: 'Settings', icon: Settings }, ], }, ]; function NavGroupSection({ group, pathname, collapsed, open, onToggle, }: { group: NavGroup; pathname: string; collapsed: boolean; open: boolean; onToggle: () => void; }) { const Icon = group.icon; const hasActive = group.items.some( (item) => pathname === item.href || pathname.startsWith(item.href) ); return (
{(open || collapsed) && (
{group.items.map((item) => { const isActive = pathname === item.href || pathname.startsWith(item.href); const ItemIcon = item.icon; return ( {!collapsed && {item.label}} ); })}
)}
); } export default function Sidebar() { const pathname = usePathname(); const { logout } = useAuth(); const [collapsed, setCollapsed] = useState(false); const [openGroups, setOpenGroups] = useState>(() => { // All groups open by default const defaults: Record = {}; navigation.forEach((entry) => { if (isGroup(entry)) defaults[entry.label] = true; }); return defaults; }); const toggleGroup = (label: string) => { setOpenGroups((prev) => ({ ...prev, [label]: !prev[label] })); }; return ( ); }