import { useState, useEffect } from 'react' import { NavLink, useLocation } from 'react-router-dom' import { Gauge, LayoutGrid, Wrench, Bell, Settings, Menu, LogOut } from 'lucide-react' import { useAuth } from './AuthGate' import { can } from '../types' const ICON_PROPS = { size: 16, strokeWidth: 1.75 } const NAV = [ { to: '/dashboard', label: 'Dashboard', icon: LayoutGrid, cap: 'view' }, { to: '/assets', label: 'Assets', icon: Wrench, cap: 'manage_assets' }, { to: '/alerts', label: 'Alerts', icon: Bell, cap: 'view' }, { to: '/settings', label: 'Settings', icon: Settings, cap: 'settings' }, ] export default function Layout({ children }: { children: React.ReactNode }) { const { user } = useAuth() const items = NAV.filter(n => can(user, n.cap)) const location = useLocation() const [menuOpen, setMenuOpen] = useState(false) async function logout() { await fetch('/plant/api/auth/logout', { method: 'POST', credentials: 'include' }) window.location.reload() } useEffect(() => { setMenuOpen(false) }, [location.pathname]) return (
{menuOpen &&
setMenuOpen(false)} />}
Plant Room
{children}
) }