import { useState } from "react"; import { TransitionProps } from "@mui/material/transitions"; import logotip from "../../assets/Icons/logoPenaHab.svg"; import logotipBlack from "../../assets/Icons/black_logo_PenaHab.svg"; import CustomAvatar from "./Avatar"; import CloseIcon from "../icons/CloseIcons"; import React from "react"; import { AppBar, Box, Button, Dialog, IconButton, List, ListItem, Slide, Toolbar, Typography, useMediaQuery, useTheme, } from "@mui/material"; import { Link, useLocation } from "react-router-dom"; import { useUserStore } from "@root/stores/user"; import { currencyFormatter } from "@root/utils/currencyFormatter"; type MenuItem = { name: string; url: string; subMenu?: MenuItem[]; }; const arrayMenu: MenuItem[] = [ { name: "Тарифы", url: "/tariffs", subMenu: [ { name: "Тарифы на время", url: "/tariffs/time" }, { name: "Тарифы на объём", url: "/tariffs/volume" }, { name: "Кастомный тариф", url: "/tariffconstructor" }, ], }, { name: "Вопросы и ответы", url: "/faq" }, { name: "Корзина", url: "/basket" }, { name: "История", url: "/history" }, ]; const Transition = React.forwardRef(function Transition( props: TransitionProps & { children: React.ReactElement; }, ref: React.Ref ) { return ; }); interface DialogMenuProps { open: boolean; handleClose: () => void; } export default function DialogMenu({ open, handleClose }: DialogMenuProps) { const [activeSubMenuIndex, setActiveSubMenuIndex] = useState(-1); const theme = useTheme(); const location = useLocation(); const isMobile = useMediaQuery(theme.breakpoints.down(600)); const user = useUserStore((state) => state.user); const cash = useUserStore((state) => state.userAccount?.wallet.cash) ?? 0; const closeDialogMenu = () => { setActiveSubMenuIndex(-1); handleClose(); }; const handleSubMenu = (index: number) => setActiveSubMenuIndex((activeIndex) => activeIndex !== index ? index : -1 ); return ( {isMobile && ( icon )} {arrayMenu.map(({ name, url, subMenu = [] }, index) => ( {subMenu.length ? ( {index === activeSubMenuIndex && subMenu.map(({ name, url }) => ( {name} ))} ) : ( <> )} ))} {isMobile ? ( location.pathname === "/" ? ( ) : ( Мой баланс {currencyFormatter.format(cash / 100)} ) ) : ( icon )} ); }