import * as React from "react"; import { useLocation, matchPath } from "react-router-dom"; import { AppBar, Toolbar, Typography, IconButton, Tooltip, Button, Box, useMediaQuery, useTheme, } from "@mui/material"; import MenuIcon from "@mui/icons-material/Menu"; import LogoutIcon from "@mui/icons-material/Logout"; import DarkModeIcon from "@mui/icons-material/DarkMode"; import LightModeIcon from "@mui/icons-material/LightMode"; import { useNavigate } from "react-router-dom"; import { useAuth } from "../react-auth"; import { ColorModeContext } from "./AppTheme"; interface HeaderProps { routerMapping: { path: string; headerTitle: string; }[]; onDrawerToggle?: () => void; } export default function Header({ routerMapping, onDrawerToggle, }: HeaderProps) { const location = useLocation(); const matchedRoute = routerMapping.find((route) => matchPath({ path: route.path, end: false }, location.pathname) ); const headerTitle = matchedRoute?.headerTitle ?? "Khata"; const navigate = useNavigate(); const { currentUser, logout } = useAuth(); const { mode, toggleColorMode } = React.useContext(ColorModeContext); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("md")); const isAuthenticated = !!currentUser; return ( theme.zIndex.drawer + 1, backdropFilter: "blur(8px)", boxShadow: "none", borderBottom: "1px solid", borderColor: "divider", }} > {/* MOBILE MENU BUTTON */} {isMobile && onDrawerToggle && ( )} {/* THEME TOGGLE */} {mode === 'dark' ? : } {/* TITLE */} navigate("/")} > {headerTitle} {/* AUTH SECTION */} {isAuthenticated ? ( <> ) : ( )} ); }