
import React from 'react';
import { HashRouter as Router, Routes, Route, Link, useLocation } from 'react-router-dom';
import { Bot, Phone, Book, User, LayoutDashboard, Mic2, Video, GitBranch } from 'lucide-react';

import { AssistantsPage } from './pages/Assistants';
import { KnowledgeBasePage } from './pages/KnowledgeBase';
import { CallLogsPage } from './pages/CallLogs';
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';

const SidebarItem: React.FC<{ to: string; icon: React.ReactNode; label: string; active: boolean }> = ({ to, icon, label, active }) => (
  <Link 
    to={to} 
    className={`flex items-center space-x-3 px-4 py-3 rounded-md transition-all duration-200 ${active ? 'bg-primary/20 text-primary border-r-2 border-primary' : 'text-muted-foreground hover:bg-muted/50 hover:text-foreground'}`}
  >
    {icon}
    <span className="font-medium text-sm">{label}</span>
  </Link>
);

const AppLayout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
  const location = useLocation();

  const navItems = [
    { path: '/', label: '首页', icon: <LayoutDashboard className="h-5 w-5" /> },
    { path: '/assistants', label: '小助手', icon: <Bot className="h-5 w-5" /> },
    { path: '/voices', label: '声音库', icon: <Mic2 className="h-5 w-5" /> },
    { path: '/call-logs', label: '视频通话记录', icon: <Phone className="h-5 w-5" /> },
    { path: '/knowledge', label: '知识库', icon: <Book className="h-5 w-5" /> },
    { path: '/workflows', label: '工作流', icon: <GitBranch className="h-5 w-5" /> },
    { path: '/profile', label: '个人中心', icon: <User className="h-5 w-5" /> },
  ];

  return (
    <div className="flex h-screen overflow-hidden">
      {/* Sidebar with Glass effect */}
      <aside className="w-64 border-r border-border/40 bg-card/30 backdrop-blur-md hidden md:flex flex-col">
        <div className="p-6 flex items-center space-x-3 border-b border-border/40 overflow-hidden">
          <div className="h-10 w-10 shrink-0 bg-gradient-to-br from-cyan-400 to-blue-600 rounded-xl flex items-center justify-center shadow-[0_0_20px_rgba(6,182,212,0.5)] border border-white/10">
             <Video className="h-6 w-6 text-white drop-shadow-md" />
          </div>
          <span className="text-lg font-bold tracking-wide whitespace-nowrap bg-clip-text text-transparent bg-gradient-to-r from-white to-white/80">
            AI VideoAssistant
          </span>
        </div>
        <nav className="flex-1 p-4 space-y-2">
          {navItems.map(item => (
            <SidebarItem 
              key={item.path} 
              to={item.path} 
              icon={item.icon} 
              label={item.label} 
              active={item.path === '/' ? location.pathname === '/' : location.pathname.startsWith(item.path)} 
            />
          ))}
        </nav>
        <div className="p-4 border-t border-border/40 text-xs text-muted-foreground text-center font-mono">
          SYSTEM v2.0
        </div>
      </aside>

      {/* Main Content */}
      <main className="flex-1 flex flex-col overflow-hidden relative">
         <header className="h-16 border-b border-border/40 flex items-center px-6 bg-card/30 backdrop-blur-md md:hidden space-x-3">
             <div className="h-8 w-8 bg-gradient-to-br from-cyan-400 to-blue-600 rounded-lg flex items-center justify-center shadow-lg">
                <Video className="h-5 w-5 text-white" />
             </div>
             <span className="font-bold text-lg whitespace-nowrap">AI VideoAssistant</span>
         </header>
         <div className="flex-1 overflow-auto p-4 md:p-6">
            {children}
         </div>
      </main>
    </div>
  );
};

const App: React.FC = () => {
  return (
    <Router>
      <AppLayout>
        <Routes>
          <Route path="/" element={<DashboardPage />} />
          <Route path="/assistants" element={<AssistantsPage />} />
          <Route path="/voices" element={<VoiceLibraryPage />} />
          <Route path="/knowledge" element={<KnowledgeBasePage />} />
          <Route path="/call-logs" element={<CallLogsPage />} />
          <Route path="/workflows" element={<WorkflowsPage />} />
          <Route path="/workflows/new" element={<WorkflowEditorPage />} />
          <Route path="/workflows/edit/:id" element={<WorkflowEditorPage />} />
          <Route path="/profile" element={<ProfilePage />} />
        </Routes>
      </AppLayout>
    </Router>
  );
};

export default App;
