import { useState, useEffect } from "react" // react-router components // import { useLocation, Link } from "react-router-dom" // nextjs components import Link from "next/link" import { useRouter, NextRouter } from "next/router" // @material-ui core components import AppBar from "@mui/material/AppBar" import Toolbar from "@mui/material/Toolbar" import IconButton from "@mui/material/IconButton" import Menu from "@mui/material/Menu" import Icon from "@mui/material/Icon" // ThreeD Garden components import MDBox from "~/components/mui/MDBox" import MDInput from "~/components/mui/MDInput" import MDBadge from "~/components/mui/MDBadge" // ThreeD Garden examples components import Breadcrumbs from "~/components/elements/Breadcrumbs" import NotificationItem from "~/components/elements/Items/NotificationItem" // Custom styles for DashboardNavbar import { navbar, navbarContainer, navbarRow, navbarIconButton, navbarDesktopMenu, navbarMobileMenu, } from "~/components/elements/Navbars/DashboardNavbar/styles" // ThreeD Garden context import { useMaterialUIController, setTransparentNavbar, setMiniSidenav, setOpenConfigurator, } from "~/context" // Declaring prop types for DashboardNavbar interface Props { absolute?: boolean light?: boolean isMini?: boolean } function DashboardNavbar({ absolute, light, isMini }: Props): JSX.Element { const [navbarType, setNavbarType] = useState< "fixed" | "absolute" | "relative" | "static" | "sticky" >() const [controller, dispatch] = useMaterialUIController() const { miniSidenav, transparentNavbar, fixedNavbar, openConfigurator, darkMode, } = controller const [openMenu, setOpenMenu] = useState(false) // const route = useLocation().pathname.split("/").slice(1) const { pathname } = useRouter() const route = pathname.split("/").slice(1) useEffect(() => { // Setting the navbar type if (fixedNavbar) { setNavbarType("sticky") } else { setNavbarType("static") } // A function that sets the transparent state of the navbar. function handleTransparentNavbar() { setTransparentNavbar( dispatch, (fixedNavbar && window.scrollY === 0) || !fixedNavbar ) } /** The event listener that's calling the handleTransparentNavbar function when scrolling the window. */ window.addEventListener("scroll", handleTransparentNavbar) // Call the handleTransparentNavbar function to set the state with the initial value. handleTransparentNavbar() // Remove event listener on cleanup return () => window.removeEventListener("scroll", handleTransparentNavbar) }, [dispatch, fixedNavbar]) const handleMiniSidenav = () => setMiniSidenav(dispatch, !miniSidenav) const handleConfiguratorOpen = () => setOpenConfigurator(dispatch, !openConfigurator) const handleOpenMenu = (event: any) => setOpenMenu(event.currentTarget) const handleCloseMenu = () => setOpenMenu(false) // Render the notifications menu const renderMenu = () => ( email} title="Check Messages" /> podcasts} title="Manage Sessions" /> shopping_cart} title="Shopping Cart" /> ) // Styles for the navbar icons const iconsStyle = ({ palette: { dark, white, text }, functions: { rgba }, }: { palette: any functions: any }) => ({ color: () => { let colorValue = light || darkMode ? white.main : dark.main if (transparentNavbar && !light) { colorValue = darkMode ? rgba(text.main, 0.6) : text.main } return colorValue }, }) return ( navbar(theme, { transparentNavbar, absolute, light, darkMode }) }> navbarRow(theme, { isMini })} > {miniSidenav ? "menu" : "menu_open"} {/* */} {isMini ? null : ( navbarRow(theme, { isMini })}> {/* */} {/* {miniSidenav ? "menu_open" : "menu"} */} notifications settings account_circle {renderMenu()} )} ) } // Declaring default props for DashboardNavbar DashboardNavbar.defaultProps = { absolute: false, light: false, isMini: false, } export default DashboardNavbar