import React, { useState, useEffect } from 'react'; import { HashRouter as Router, Routes, Route, Link, useLocation } from 'react-router-dom'; import { Bot, Book, User, LayoutDashboard, Mic2, Video, GitBranch, Zap, PanelLeftClose, PanelLeftOpen, History as HistoryIcon, ChevronDown, ChevronRight, Box, Wand2, Wrench, BrainCircuit, AudioLines, Activity } from 'lucide-react'; import { AssistantsPage } from './pages/Assistants'; import { KnowledgeBasePage } from './pages/KnowledgeBase'; import { HistoryPage } from './pages/History'; import { ProfilePage } from './pages/Profile'; import { DashboardPage } from './pages/Dashboard'; import { VoiceLibraryPage } from './pages/VoiceLibrary'; import { WorkflowsPage } from './pages/Workflows'; import { WorkflowEditorPage } from './pages/WorkflowEditor'; import { AutoTestPage } from './pages/AutoTest'; import { ToolLibraryPage } from './pages/ToolLibrary'; import { LLMLibraryPage } from './pages/LLMLibrary'; import { ASRLibraryPage } from './pages/ASRLibrary'; type NavItemType = { path: string; label: string; icon: React.ReactNode; children?: NavItemType[]; }; const SidebarItem: React.FC<{ item: NavItemType; isActive: boolean; isCollapsed: boolean; onExpand: () => void; }> = ({ item, isActive, isCollapsed, onExpand }) => { const location = useLocation(); const [isOpen, setIsOpen] = useState(false); const hasChildren = item.children && item.children.length > 0; // Check if any child is active to auto-expand const isChildActive = hasChildren && item.children!.some(child => location.pathname.startsWith(child.path)); useEffect(() => { if (isChildActive) { setIsOpen(true); } }, [isChildActive]); const handleClick = (e: React.MouseEvent) => { if (hasChildren) { e.preventDefault(); if (isCollapsed) { onExpand(); setIsOpen(true); } else { setIsOpen(!isOpen); } } }; const activeClass = "bg-primary/20 text-primary border-r-2 border-primary"; const inactiveClass = "text-muted-foreground hover:bg-muted/50 hover:text-foreground"; if (hasChildren) { return (