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 (
{/* Mobile sidebar */}
setSidebarOpen(false)} />
{/* Static sidebar for desktop */}
{/* Main content */}
{/* Top navigation */}

{navigation?.find(item => item.href === location.pathname)?.name || 'Drone Detection System'}

{/* Connection status */}
{connected ? ( ) : ( )} {connected ? 'Connected' : 'Disconnected'}
{/* Recent detections count */} {recentDetections.length > 0 && (
{recentDetections.length} recent
)} {/* User menu */}
{user?.username}
{/* Page content */}
{/* Debug Toggle (floating button) */}
); }; const SidebarContent = ({ navigation }) => { const location = useLocation(); return ( <>

Drone Detector

); }; export default Layout;