import React, { useState, useEffect, useRef } from "react"; import FullLogo from '../../assets/images/logo.svg?react'; import MiniLogo from '../../assets/images/system_monitor_icon.svg?react'; import { Drawer, List, Typography, styled, IconButton, Tooltip, Box } from "@mui/material"; import { ChevronLeft, ChevronRight, Menu as MenuIcon } from "@mui/icons-material"; import MenuItem from "./SidebarMenuComponents/MenuItem"; import SidebarFooter from "./SidebarMenuComponents/SidebarFooter"; import { statusManager1 } from "../TreeChart/dataUtils"; import tabContent from "../TreeChart/tabContent"; const SidebarResizer = styled('div')(({ theme }) => ({ width: "5px", cursor: "ew-resize", backgroundColor: 'transparent', height: "100%", position: "absolute", right: 0, top: 0, transition: 'background-color 0.2s', '&:hover': { backgroundColor: theme.palette.primary.main, }, zIndex: 2 })); const SidebarMenu = ({ data, onOpenTab, sidebarWidth, startResizing, collapsed, setCollapsed, isDarkMode, setIsDarkMode }) => { const [hovered, setHovered] = useState(false); const [menuData, setMenuData] = useState(data); const contentCache = useRef({}); useEffect(() => { if (data) { const dataCopy = JSON.parse(JSON.stringify(data)); statusManager1.updateStatuses(dataCopy); setMenuData(dataCopy); } }, [data]); const handleToggleCollapse = () => { setCollapsed(!collapsed); }; const handleSelectItem = (id, title, children) => { onOpenTab(id, title); contentCache.current = tabContent({ items: children }, contentCache.current); if (contentCache.current[id]) { onOpenTab(id, title, contentCache.current[id].content); } }; const drawerWidth = collapsed ? 64 : sidebarWidth; return ( setHovered(true)} onMouseLeave={() => setHovered(false)} sx={{ position: 'relative', width: drawerWidth, transition: 'width 0.3s ease', }} > {/* Верхняя часть с логотипом и кнопкой */} {/* Логотип - центрируется в доступном пространстве */} {/* Мини-логотип (только в свернутом состоянии) */} {collapsed && ( )} {/* Кнопка сворачивания/разворачивания */} {collapsed ? : } {/* Содержимое меню */} {!collapsed && ( Меню )} {menuData && ( )} {/* Футер */} {/* Ресайзер */} {!collapsed && ( )} ); }; export default SidebarMenu;