import { Outlet, useLocation, useNavigate } from 'react-router'; import { useEffect, useState, useSyncExternalStore } from 'react'; import { Sidebar } from './Sidebar'; import { LogOut, Menu } from './Icons'; import { clearSession, getMe, notifyAuthChange, subscribeAuth } from '../lib/auth'; export function Layout() { const navigate = useNavigate(); const location = useLocation(); const me = useSyncExternalStore(subscribeAuth, getMe, () => null); const [drawerOpen, setDrawerOpen] = useState(false); // Defensive: close the drawer on route change in case the user opens // it then navigates via something other than the sidebar links // (e.g. the legacy importer link in PageHeader actions). The drawer // also closes via NavLink onClick → onNavigate, so this is a belt. useEffect(() => { setDrawerOpen(false); }, [location.pathname]); const logout = () => { clearSession(); notifyAuthChange(); navigate('/login', { replace: true }); }; return (