"use client"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { Bell, Bot, Boxes, Brain, ChevronLeft, ChevronUp, Clock3, Database, HelpCircle, Wrench, Home, LogOut, PlayCircle, Video, } from "lucide-react"; import { useAuth } from "@/components/auth/AuthProvider"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { ThemeModeSelector } from "./ThemeToggle"; type SidebarProps = { collapsed: boolean; onToggle: () => void; }; type NavItem = { href: string; label: string; icon: React.ComponentType<{ size?: number; className?: string }>; }; const componentSubItems: NavItem[] = [ { href: "/components/models", label: "模型资源", icon: Brain }, { href: "/components/knowledge", label: "知识库", icon: Database }, { href: "/components/tools", label: "工具资源", icon: Wrench }, ]; const monitorSubItems: NavItem[] = [ { href: "/history", label: "历史记录", icon: Clock3 }, { href: "/dashboard", label: "数据看板", icon: Database }, ]; export function Sidebar({ collapsed, onToggle }: SidebarProps) { const pathname = usePathname(); const router = useRouter(); const { user, logout } = useAuth(); // 精确匹配或前缀匹配(带 / 边界),让 /assistants/xxx 也高亮"创建助手" const isActive = (href: string) => pathname === href || pathname.startsWith(`${href}/`); const componentActive = componentSubItems.some((item) => isActive(item.href)); const monitorActive = monitorSubItems.some((item) => isActive(item.href)); async function handleLogout() { await logout(); router.replace("/login"); } return ( ); } function NavButton({ active, collapsed, icon: Icon, label, href, small = false, }: { active: boolean; collapsed: boolean; icon: React.ComponentType<{ size?: number; className?: string }>; label: string; href: string; small?: boolean; }) { return ( {label} ); }