import React, { useState } from 'react'; import { Outlet, Link, useLocation } from 'react-router-dom'; import { useAuth } from '../contexts/AuthContext'; import { useSocket } from '../contexts/SocketContext'; import DebugToggle from './DebugToggle'; import { HomeIcon, MapIcon, ServerIcon, ExclamationTriangleIcon, BellIcon, UserIcon, Bars3Icon, XMarkIcon, SignalIcon, WifiIcon, BugAntIcon } from '@heroicons/react/24/outline'; import classNames from 'classnames'; const baseNavigation = [ { name: 'Dashboard', href: '/', icon: HomeIcon }, { name: 'Map View', href: '/map', icon: MapIcon }, { name: 'Devices', href: '/devices', icon: ServerIcon }, { name: 'Detections', href: '/detections', icon: ExclamationTriangleIcon }, { name: 'Alerts', href: '/alerts', icon: BellIcon }, ]; const adminNavigation = [ { name: 'Debug', href: '/debug', icon: BugAntIcon }, ]; const Layout = () => { const [sidebarOpen, setSidebarOpen] = useState(false); const { user, logout } = useAuth(); const { connected, recentDetections } = useSocket(); const location = useLocation(); // Build navigation based on user role - ensure it's always an array const navigation = React.useMemo(() => { if (!user) { return baseNavigation; // Return base navigation if user not loaded yet } return user.role === 'admin' ? [...baseNavigation, ...adminNavigation] : baseNavigation; }, [user?.role]); return (