import React, { useState } from 'react'; import { AppBar, Toolbar, Typography, Button, IconButton, Menu, MenuItem, Avatar, Badge, Box, useTheme, useMediaQuery, Drawer, List, ListItem, ListItemButton, ListItemIcon, ListItemText, Divider, } from '@mui/material'; import { Menu as MenuIcon, Notifications as NotificationsIcon, AccountCircle, Dashboard, List as ListIcon, Inventory, Settings, AdminPanelSettings, Logout, ShoppingCart, } from '@mui/icons-material'; import { useNavigate, useLocation } from 'react-router-dom'; import { useAuth } from '../../contexts/AuthContext'; import { useQuery } from '@tanstack/react-query'; import { notificationsAPI } from '../../services/api'; const Navbar: React.FC = () => { const navigate = useNavigate(); const location = useLocation(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('md')); const { user, logout, isAuthenticated } = useAuth(); const [anchorEl, setAnchorEl] = useState(null); const [mobileOpen, setMobileOpen] = useState(false); // Get unread notifications count const { data: unreadCount } = useQuery({ queryKey: ['notifications', 'unread-count'], queryFn: () => notificationsAPI.getUnreadCount(), enabled: isAuthenticated, refetchInterval: 30000, // Refetch every 30 seconds }); const handleProfileMenuOpen = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleMenuClose = () => { setAnchorEl(null); }; const handleDrawerToggle = () => { setMobileOpen(!mobileOpen); }; const handleLogout = () => { logout(); handleMenuClose(); navigate('/login'); }; const menuItems = [ { text: 'Anasayfa', icon: , path: '/dashboard' }, { text: 'Listeler', icon: , path: '/lists' }, { text: 'Ürünler', icon: , path: '/products' }, ]; if (user?.role === 'ADMIN') { menuItems.push({ text: 'Yönetim', icon: , path: '/admin' }); } const drawer = ( hMarket {menuItems.map((item) => ( { navigate(item.path); setMobileOpen(false); }} selected={location.pathname === item.path} > {item.icon} ))} { navigate('/profile'); setMobileOpen(false); }} selected={location.pathname === '/profile'} > ); if (!isAuthenticated) { return ( hMarket ); } return ( <> {isMobile && ( )} navigate('/dashboard')} > hMarket {!isMobile && ( {menuItems.map((item) => ( ))} )} navigate('/notifications')}> {user?.avatar ? ( ) : ( )} {/* Mobile drawer */} {drawer} {/* Profile menu */} { navigate('/profile'); handleMenuClose(); }}> Profil Çıkış ); }; export default Navbar;