import { Award, Briefcase, CalendarDays, ChevronDown, ClipboardList, LayoutDashboard, Shield, UserRound, Users, } from "lucide-react"; import { useEffect, useRef, useState, type ComponentType } from "react"; import { NavLink, Outlet, useLocation } from "react-router-dom"; import { useAuth } from "../../auth"; const navItems = [ { to: "/people", label: "People" }, { to: "/projects", label: "Projects" }, ]; interface ManageItem { to: string; label: string; icon: ComponentType<{ size?: number; className?: string }>; } const manageGroups: ManageItem[][] = [ [ { to: "/manage", label: "Manage Hub", icon: LayoutDashboard }, ], [ { to: "/manage/people", label: "People", icon: UserRound }, { to: "/manage/projects", label: "Projects", icon: ClipboardList }, ], [ { to: "/manage/roles", label: "Roles", icon: Briefcase }, { to: "/manage/teams", label: "Teams", icon: Users }, { to: "/manage/skills", label: "Skills", icon: Award }, ], [ { to: "/manage/holidays", label: "Holidays", icon: CalendarDays }, { to: "/manage/users", label: "Users", icon: Shield }, ], ]; const tailNavItems = [ { to: "/reports", label: "Reports" }, { to: "/insights", label: "Insights" }, ]; export function Layout() { const { logout, user } = useAuth(); const location = useLocation(); const [menuOpen, setMenuOpen] = useState(false); const [manageOpen, setManageOpen] = useState(false); const manageRef = useRef(null); const closeTimer = useRef(undefined); const isManageActive = location.pathname === "/manage" || location.pathname.startsWith("/manage/"); useEffect(() => { setManageOpen(false); }, [location.pathname]); useEffect(() => { if (!menuOpen) return; const onClick = (event: MouseEvent) => { const target = event.target as HTMLElement; if (!target.closest(".topnav-actions")) setMenuOpen(false); }; document.addEventListener("mousedown", onClick); return () => document.removeEventListener("mousedown", onClick); }, [menuOpen]); useEffect(() => { if (!manageOpen) return; const handler = (event: MouseEvent) => { if (manageRef.current && !manageRef.current.contains(event.target as Node)) { setManageOpen(false); } }; document.addEventListener("mousedown", handler); return () => document.removeEventListener("mousedown", handler); }, [manageOpen]); const openManage = () => { if (closeTimer.current) window.clearTimeout(closeTimer.current); setManageOpen(true); }; const scheduleCloseManage = () => { if (closeTimer.current) window.clearTimeout(closeTimer.current); closeTimer.current = window.setTimeout(() => setManageOpen(false), 140); }; return (
R
Resource Portal Internal IT
{menuOpen ? (
) : null}
); }