import { Navigate, NavLink, Outlet, useLocation, useNavigate } from 'react-router-dom'
import { Avatar, Button, Separator } from '@heroui/react'
import { House, Rocket, Gear, FileText } from '@gravity-ui/icons'
import { useAuth } from '../auth/auth'
interface NavItem { id: string; label: string; description: string; icon: any }
export function AppLayout() {
const { token, username, logout } = useAuth()
const navigate = useNavigate()
const location = useLocation()
const navItems: NavItem[] = [
{ id: 'home', label: '首页', description: '主机与服务状态', icon: House },
{ id: 'plugins', label: '插件管理', description: '插件总览与分群控制', icon: Rocket },
{ id: 'logs', label: '查看日志', description: 'bot 运行日志实时查看', icon: FileText },
{ id: 'settings', label: '设置', description: '账号与系统设置', icon: Gear },
]
const path = location.pathname.replace(/\/+$/, '') || '/'
const isHome = path === '/hub'
const isSettings = path.startsWith('/hub/settings')
const isLogs = path.startsWith('/hub/logs')
const isPluginList = path.startsWith('/hub/plugins')
const isPlugins = isPluginList || (!isHome && !isSettings && !isLogs && path.startsWith('/hub/'))
const isPluginSub = isPlugins && !isPluginList
const activeId = isPlugins ? 'plugins' : isLogs ? 'logs' : isSettings ? 'settings' : 'home'
const pageMeta = navItems.find(it => it.id === activeId) || navItems[0]
if (!token) return