import { useState } from "react"; import { AppBar, Avatar, Box, Divider, Drawer, IconButton, List, ListItemButton, ListItemIcon, ListItemText, Menu, MenuItem, Stack, Toolbar, Typography, useMediaQuery, } from "@mui/material"; import { useTheme } from "@mui/material/styles"; import MenuRoundedIcon from "@mui/icons-material/MenuRounded"; import DashboardRoundedIcon from "@mui/icons-material/DashboardRounded"; import EngineeringRoundedIcon from "@mui/icons-material/EngineeringRounded"; import PeopleRoundedIcon from "@mui/icons-material/PeopleRounded"; import CategoryRoundedIcon from "@mui/icons-material/CategoryRounded"; import EventNoteRoundedIcon from "@mui/icons-material/EventNoteRounded"; import StarRoundedIcon from "@mui/icons-material/StarRounded"; import LogoutRoundedIcon from "@mui/icons-material/LogoutRounded"; import HandymanRoundedIcon from "@mui/icons-material/HandymanRounded"; import { NavLink, Outlet, useLocation } from "react-router-dom"; import { useAuth } from "@/auth/AuthContext"; import { initials } from "@/utils/format"; const DRAWER_WIDTH = 256; const NAV = [ { to: "/", label: "Dashboard", icon: }, { to: "/workers", label: "Workers", icon: }, { to: "/customers", label: "Customers", icon: }, { to: "/categories", label: "Categories", icon: }, { to: "/bookings", label: "Bookings", icon: }, { to: "/reviews", label: "Reviews", icon: }, ]; export default function Layout() { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("md")); const [mobileOpen, setMobileOpen] = useState(false); const [anchor, setAnchor] = useState(null); const { user, logout } = useAuth(); const location = useLocation(); const title = NAV.find((n) => n.to === location.pathname)?.label ?? "Admin"; const drawer = ( Labour Connect Admin Panel {NAV.map((item) => ( isMobile && setMobileOpen(false)} sx={{ borderRadius: 2.5, mb: 0.5, color: "text.secondary", "&.active": { bgcolor: "primary.light", color: "primary.main", fontWeight: 700, "& .MuiListItemIcon-root": { color: "primary.main" }, }, }} > {item.icon} ))} ); return ( setMobileOpen(true)} sx={{ mr: 2, display: { md: "none" } }} > {title} setAnchor(e.currentTarget)}> {initials(user?.name)} setAnchor(null)} anchorOrigin={{ vertical: "bottom", horizontal: "right" }} transformOrigin={{ vertical: "top", horizontal: "right" }} > {user?.name} {user?.email} Log out setMobileOpen(false)} ModalProps={{ keepMounted: true }} sx={{ display: { xs: "block", md: "none" }, "& .MuiDrawer-paper": { width: DRAWER_WIDTH, boxSizing: "border-box" }, }} > {drawer} {drawer} ); }