import React from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; import { Drawer, List, ListItem, ListItemIcon, ListItemText, Box, useTheme, Typography } from '@mui/material'; import { DashboardRounded as DashboardIcon, PointOfSale as CashierIcon, AllInbox as SupplierIcon, Store as InventoryIcon, School as TrainingIcon, AutoGraph as AnalyticsIcon, Restaurant as RestaurantIcon, CountertopsTwoTone as HostKitchenIcon, Queue as CreateKitchenIcon, Settings as SettingsIcon, Logout as LogoutIcon } from '@mui/icons-material'; import authService from '../../services/authService'; // تأكد من المسار الصحيح const menuItems = [ { text: 'Dashboard', icon: , path: '/dashboard' }, { text: 'Cashier', icon: , path: '/cashier' }, { text: 'Supplier', icon: , path: '/supplier' }, { text: 'Inventory', icon: , path: '/inventory' }, { text: 'Training', icon: , path: '/training' }, { text: 'Analytics & Reporting', icon: , path: '/analytics' }, { text: 'Restaurant Profile', icon: , path: '/profile' }, // { text: 'Host Kitchen', icon: , path: '/host-kitchen' }, { text: 'Create Kitchen', icon: , path: '/create-kitchen' }, ]; const bottomItems = [ { text: 'Settings', icon: , path: '/settings' }, { text: 'Log Out', icon: , path: '/login' }, ]; const Sidebar = ({ open, onClose, isMobile, drawerWidth }) => { const theme = useTheme(); const navigate = useNavigate(); const location = useLocation(); const handleLogout = async () => { const result = await authService.logout(); localStorage.removeItem('token'); localStorage.removeItem('refresh_token'); navigate('/login', { replace: true }); if (isMobile) onClose(); }; const renderListItems = (items) => items.map((item, index) => { const isActive = location.pathname === item.path; return ( { if (item.text === 'Log Out') { handleLogout(); } else { navigate(item.path); if (isMobile) onClose(); } }} sx={{ display: 'flex', alignItems: 'center', width: '100%', borderRadius: '5px', backgroundColor: isActive ? '#F8F6F8' : 'transparent', px: 2, py: 1, cursor: 'pointer', transition: 'background-color 0.2s', '&:hover': { backgroundColor: '#fffcf9d5', }, }} > {item.icon} ); }); const drawer = ( KITCH PLUS {renderListItems(menuItems)} {renderListItems(bottomItems)} ); return ( {drawer} ); }; export default Sidebar;