import { Link, useLocation } from 'react-router-dom' import { cn } from '@/lib/utils' import { LayoutDashboard, TestTube2, Link as LinkIcon, Key, DollarSign, Database, Github, Moon, Sun, LogIn, LogOut, } from 'lucide-react' import { useAuthStore } from '@/store/auth' import { useState } from 'react' import { Button } from '../ui/button' interface NavItem { title: string href: string icon: React.ComponentType<{ className?: string }> adminOnly?: boolean } const navItems: NavItem[] = [ { title: '仪表盘', href: '/', icon: LayoutDashboard, }, { title: 'API 测试', href: '/api-test', icon: TestTube2, }, { title: '频道管理', href: '/channels', icon: LinkIcon, adminOnly: true, }, { title: '令牌管理', href: '/tokens', icon: Key, adminOnly: true, }, { title: '定价管理', href: '/pricing', icon: DollarSign, adminOnly: true, }, { title: '数据库', href: '/database', icon: Database, adminOnly: true, }, ] interface SidebarProps { onAuthClick: () => void } export function Sidebar({ onAuthClick }: SidebarProps) { const location = useLocation() const { isAuthenticated, logout } = useAuthStore() // Initialize theme from localStorage on mount const [theme, setTheme] = useState<'light' | 'dark'>(() => { if (typeof window !== 'undefined') { const savedTheme = localStorage.getItem('theme') const isDark = savedTheme === 'dark' || (!savedTheme && document.documentElement.classList.contains('dark')) if (isDark) { document.documentElement.classList.add('dark') } return isDark ? 'dark' : 'light' } return 'light' }) const toggleTheme = () => { const newTheme = theme === 'light' ? 'dark' : 'light' setTheme(newTheme) localStorage.setItem('theme', newTheme) if (newTheme === 'dark') { document.documentElement.classList.add('dark') } else { document.documentElement.classList.remove('dark') } } const handleAuthClick = () => { if (isAuthenticated) { logout() } else { onAuthClick() } } return ( ) }