import { useState, useCallback } from "react"; import { Outlet, Navigate, useLocation } from "react-router-dom"; import { motion } from "framer-motion"; import { useAuth } from "../context/AuthContext"; import { useTheme } from "../../context/ThemeContext"; import { setLogoutAlert } from "../utils/api"; import useModalLock from "../hooks/useModalLock"; import Sidebar from "./Sidebar"; import ShortcutsHelp from "./ShortcutsHelp"; export default function AdminLayout() { const { isAuthenticated, loading, user, logout } = useAuth(); const { theme, toggleTheme } = useTheme(); const [sidebarOpen, setSidebarOpen] = useState(false); const [loggingOut, setLoggingOut] = useState(false); const location = useLocation(); // Session is managed by AuthProvider (initial check + proactive refresh via setTimeout). // Do not call checkSession on route changes — concurrent refresh calls with token rotation // would invalidate each other and kick the user out. const handleLogout = useCallback(() => { setLoggingOut(true); setSidebarOpen(false); setLogoutAlert(); setTimeout(() => logout(), 400); }, [logout]); useModalLock(sidebarOpen); if (loading) { return (