import { NavLink, useNavigate } from 'react-router-dom' import { PanelLeftClose, PanelLeftOpen } from 'lucide-react' import { NAV_ITEMS } from '@/config/navigation' import { useUiStore } from '@/app/store/ui' import { useAuthStore } from '@/app/store/auth' import { usePermission } from '@/hooks/usePermission' import { useI18n } from '@/i18n' import { cn } from '@/utils/cn' import { getPlan } from '@/config/pricingPlans' import { Progress } from '@/components/ui/feedback' import { Avatar } from '@/components/ui/avatar' import { useQuery } from '@tanstack/react-query' import { getBilling } from '@/services/api/org' export function Sidebar() { const { sidebarCollapsed, toggleSidebar, setMobileNavOpen } = useUiStore() const { t } = useI18n() const { can } = usePermission() const tenant = useAuthStore((s) => s.tenant) const user = useAuthStore((s) => s.user) const navigate = useNavigate() const { data: billing } = useQuery({ queryKey: ['billing'], queryFn: getBilling, staleTime: 300_000 }) const plan = getPlan(billing?.info.planKey ?? tenant?.plan ?? 'pro') const msgUsage = billing?.info.usage.messages const usagePct = msgUsage ? Math.round((msgUsage.used / msgUsage.total) * 100) : 0 const items = NAV_ITEMS.filter((item) => !item.permission || can(item.permission)) const groups = [ { key: 'core', label: '核心业务' }, { key: 'intelligence', label: '知识与洞察' }, { key: 'admin', label: '企业管理' }, ] as const return ( ) }