import { useState } from "react"; import { Link, useLocation } from "react-router-dom"; import { Box, Button, List, ListItem, Typography, useMediaQuery, useTheme } from "@mui/material"; import { useUserStore } from "@root/stores/user"; import { currencyFormatter } from "@root/utils/currencyFormatter"; import { cardShadow } from "@root/utils/themes/shadow"; import CustomAvatar from "./Avatar"; 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: "/settings" }, { name: "Вопросы и ответы", url: "/faq" }, { name: "Корзина", url: "/cart" }, { name: "Поддержка", url: "/support" }, { name: "История", url: "/history" }, ]; interface DialogMenuProps { handleClose: () => void; } export default function DialogMenu({ handleClose }: DialogMenuProps) { const [activeSubMenuIndex, setActiveSubMenuIndex] = useState(-1); const theme = useTheme(); const location = useLocation(); const isTablet = useMediaQuery(theme.breakpoints.down(900)); 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 ( {arrayMenu.map(({ name, url, subMenu = [] }, index) => ( {subMenu.length ? ( {index === activeSubMenuIndex && subMenu.map(({ name, url }) => ( {name} ))} ) : ( <> )} ))} {location.pathname === "/" ? ( ) : ( Мой баланс {currencyFormatter.format(cash / 100)} )} ); }