import { useEffect, useState } from "react"; import { NavLink, Outlet, useLocation } from "react-router-dom"; import { useTheme } from "next-themes"; import { Moon, Sun, Monitor, Zap, BarChart3, Bell, Bot, FileText, Key, Terminal, SquareTerminal, PanelLeftClose, PanelLeft, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; const SIDEBAR_KEY = "wakey-sidebar-collapsed"; type NavSection = { label: string; items: readonly { to: string; label: string; icon: React.ElementType; end?: boolean; }[]; }; const navSections: NavSection[] = [ { label: "Operations", items: [ { to: "/", label: "Devices", icon: Monitor, end: true }, { to: "/wake", label: "Wake Tools", icon: Zap }, ], }, { label: "Monitoring", items: [ { to: "/dashboard", label: "Fleet Health", icon: BarChart3 }, { to: "/alerts", label: "Alerts", icon: Bell }, ], }, { label: "Admin", items: [ { to: "/agents", label: "Agents", icon: Bot }, { to: "/audit", label: "Audit", icon: FileText }, { to: "/tokens", label: "Tokens", icon: Key }, { to: "/commands", label: "Commands", icon: Terminal }, { to: "/terminal", label: "Terminal", icon: SquareTerminal }, ], }, ]; function usePageTitle() { const { pathname } = useLocation(); useEffect(() => { const flat = navSections.flatMap((s) => s.items); const match = flat.find((item) => item.end ? pathname === "/ui" || pathname === "/ui/" || pathname === "/" : pathname.startsWith(item.to) && item.to !== "/", ); document.title = match ? `${match.label} — Wakey` : "Wakey Operator UI"; }, [pathname]); } export function AppLayout() { const { resolvedTheme, setTheme } = useTheme(); const isDark = resolvedTheme === "dark"; const [collapsed, setCollapsed] = useState(() => { return window.localStorage.getItem(SIDEBAR_KEY) === "true"; }); usePageTitle(); useEffect(() => { window.localStorage.setItem(SIDEBAR_KEY, String(collapsed)); }, [collapsed]); return (