2023-07-25 22:31:04 +00:00
|
|
|
import { useState } from "react";
|
2023-03-27 12:45:44 +00:00
|
|
|
import { Box, Typography, useTheme } from "@mui/material";
|
|
|
|
import { Link, useLocation } from "react-router-dom";
|
|
|
|
|
2023-07-25 22:31:04 +00:00
|
|
|
type MenuItem = {
|
|
|
|
name: string;
|
|
|
|
url: string;
|
|
|
|
subMenu?: MenuItem[];
|
|
|
|
};
|
|
|
|
|
2023-03-27 12:45:44 +00:00
|
|
|
export default function Menu() {
|
2023-07-25 22:31:04 +00:00
|
|
|
const [activeSubMenu, setActiveSubMenu] = useState<MenuItem[]>([]);
|
2023-03-27 12:45:44 +00:00
|
|
|
const theme = useTheme();
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
const color = location.pathname === "/" ? "white" : "black";
|
|
|
|
|
2023-07-25 22:31:04 +00:00
|
|
|
const arrayMenu: MenuItem[] = [
|
|
|
|
{
|
|
|
|
name: "Тарифы",
|
|
|
|
url: "/tariffs",
|
|
|
|
subMenu: [
|
|
|
|
{ name: "Тарифы на время", url: "/tariffs/time" },
|
|
|
|
{ name: "Тарифы на объём", url: "/tariffs/volume" },
|
|
|
|
{ name: "Кастомный тариф", url: "/tariffconstructor" },
|
|
|
|
],
|
|
|
|
},
|
2023-03-27 12:45:44 +00:00
|
|
|
{ name: "Вопросы и ответы", url: "/faq" },
|
2023-08-01 00:56:03 +00:00
|
|
|
{ name: "Корзина", url: "/cart" },
|
|
|
|
{ name: "Поддержка", url: "/support" },
|
2023-07-28 13:24:21 +00:00
|
|
|
{ name: "История", url: "/history" },
|
2023-03-27 12:45:44 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
display: "flex",
|
2023-07-25 22:31:04 +00:00
|
|
|
alignItems: "center",
|
|
|
|
height: "100%",
|
2023-03-27 12:45:44 +00:00
|
|
|
gap: "30px",
|
|
|
|
overflow: "hidden",
|
|
|
|
}}
|
|
|
|
>
|
2023-08-08 15:47:02 +00:00
|
|
|
{location.pathname !== "/"
|
|
|
|
? arrayMenu.map(({ name, url, subMenu = [] }) => (
|
|
|
|
<Link
|
|
|
|
key={name}
|
|
|
|
style={{
|
|
|
|
textDecoration: "none",
|
|
|
|
height: "100%",
|
|
|
|
display: "flex",
|
|
|
|
alignItems: "center",
|
|
|
|
}}
|
|
|
|
to={url}
|
|
|
|
onMouseEnter={() => setActiveSubMenu(subMenu)}
|
|
|
|
state={{ previousUrl: location.pathname }}
|
|
|
|
>
|
|
|
|
<Typography
|
|
|
|
color={
|
|
|
|
location.pathname === url
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
: color
|
|
|
|
}
|
|
|
|
variant="body2"
|
|
|
|
sx={{
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</Typography>
|
|
|
|
</Link>
|
|
|
|
))
|
|
|
|
: arrayMenu.map(({ name, url, subMenu = [] }) => (
|
2023-07-25 22:31:04 +00:00
|
|
|
<Typography
|
|
|
|
color={
|
|
|
|
location.pathname === url
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
: color
|
|
|
|
}
|
|
|
|
variant="body2"
|
|
|
|
sx={{
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</Typography>
|
2023-08-08 15:47:02 +00:00
|
|
|
))}
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
zIndex: "10",
|
|
|
|
position: "absolute",
|
|
|
|
top: "80px",
|
|
|
|
left: 0,
|
|
|
|
backgroundColor: theme.palette.background.paper,
|
|
|
|
width: "100%",
|
|
|
|
}}
|
|
|
|
onMouseLeave={() => setActiveSubMenu([])}
|
|
|
|
>
|
|
|
|
{location.pathname !== "/" &&
|
|
|
|
activeSubMenu.map(({ name, url }) => (
|
|
|
|
<Link key={name} style={{ textDecoration: "none" }} to={url}>
|
|
|
|
<Typography
|
|
|
|
color={
|
|
|
|
location.pathname === url
|
|
|
|
? theme.palette.brightPurple.main
|
|
|
|
: color
|
|
|
|
}
|
|
|
|
variant="body2"
|
|
|
|
sx={{
|
|
|
|
padding: "15px",
|
|
|
|
whiteSpace: "nowrap",
|
|
|
|
paddingLeft: "185px",
|
|
|
|
"&:hover": {
|
|
|
|
color: theme.palette.brightPurple.main,
|
|
|
|
background: theme.palette.background.default,
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</Typography>
|
|
|
|
</Link>
|
|
|
|
))}
|
2023-07-25 22:31:04 +00:00
|
|
|
</Box>
|
2023-03-27 12:45:44 +00:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|