import { ReactNode, useEffect, useState } from 'react' import { Link, useLocation } from 'react-router-dom' import { LayoutDashboard, Radio, Cloud, Settings, Bell, } from 'lucide-react' import { fetchStatus, type SystemStatus } from '@/lib/api' import { useWebSocket } from '@/hooks/useWebSocket' interface LayoutProps { children: ReactNode } const navItems = [ { path: '/', label: 'Dashboard', icon: LayoutDashboard }, { path: '/mesh', label: 'Mesh', icon: Radio }, { path: '/environment', label: 'Environment', icon: Cloud }, { path: '/config', label: 'Config', icon: Settings }, { path: '/alerts', label: 'Alerts', icon: Bell }, ] function formatUptime(seconds: number): string { const days = Math.floor(seconds / 86400) const hours = Math.floor((seconds % 86400) / 3600) const mins = Math.floor((seconds % 3600) / 60) if (days > 0) return `${days}d ${hours}h` if (hours > 0) return `${hours}h ${mins}m` return `${mins}m` } function getPageTitle(pathname: string): string { const item = navItems.find((i) => i.path === pathname) return item?.label || 'Dashboard' } export default function Layout({ children }: LayoutProps) { const location = useLocation() const { connected } = useWebSocket() const [status, setStatus] = useState(null) const [currentTime, setCurrentTime] = useState(new Date()) useEffect(() => { fetchStatus().then(setStatus).catch(console.error) const interval = setInterval(() => { fetchStatus().then(setStatus).catch(console.error) }, 30000) return () => clearInterval(interval) }, []) useEffect(() => { const interval = setInterval(() => setCurrentTime(new Date()), 1000) return () => clearInterval(interval) }, []) const timeStr = currentTime.toLocaleTimeString('en-US', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit', }) return (
{/* Sidebar */} {/* Main content */}
{/* Header */}

{getPageTitle(location.pathname)}

{/* Live indicator */}
{connected ? 'Live' : 'Offline'}
{/* Clock */}
{timeStr} MT
{/* Page content */}
{children}
) }