import React, { useState, useEffect } from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { LayoutDashboard, FileText, BarChart3, ChevronLeft, ChevronRight, LogIn, LogOut, Menu, X, CreditCard, MessageCircle, Award, Users, Wrench, Bell, Mail, AlertTriangle, TrendingUp } from 'lucide-react'; import useAuthStore from '../../store/useAuthStore'; import { useChatNotifications } from '../../features/notifications/contexts/ChatNotificationContext'; import { useResponsive } from '../../hooks'; import { logger } from '../utils/logger'; interface SidebarStaffProps { isCollapsed?: boolean; onToggle?: () => void; } const SidebarStaff: React.FC = ({ isCollapsed: controlledCollapsed, onToggle }) => { const [internalCollapsed, setInternalCollapsed] = useState(false); const [isMobileOpen, setIsMobileOpen] = useState(false); const location = useLocation(); const navigate = useNavigate(); const { logout } = useAuthStore(); const { unreadCount } = useChatNotifications(); const { isMobile, isDesktop } = useResponsive(); const handleLogout = async () => { try { await logout(); // Logout function will redirect to homepage if (isMobile) { setIsMobileOpen(false); } } catch (error) { logger.error('Logout error', error); } }; // Close mobile menu when screen becomes desktop useEffect(() => { if (isDesktop) { setIsMobileOpen(false); } }, [isDesktop]); const isCollapsed = controlledCollapsed !== undefined ? controlledCollapsed : internalCollapsed; const handleToggle = () => { if (onToggle) { onToggle(); } else { setInternalCollapsed(!internalCollapsed); } }; const handleMobileToggle = () => { setIsMobileOpen(!isMobileOpen); }; const handleLinkClick = () => { if (isMobile) { setIsMobileOpen(false); } }; const menuItems = [ { path: '/staff/dashboard', icon: LayoutDashboard, label: 'Dashboard' }, { path: '/staff/bookings', icon: FileText, label: 'Bookings' }, { path: '/staff/reception', icon: LogIn, label: 'Reception' }, { path: '/staff/payments', icon: CreditCard, label: 'Payments' }, { path: '/staff/loyalty', icon: Award, label: 'Loyalty Program' }, { path: '/staff/guest-profiles', icon: Users, label: 'Guest Profiles' }, { path: '/staff/guest-requests', icon: Bell, label: 'Guest Requests' }, { path: '/staff/guest-communication', icon: Mail, label: 'Communication' }, { path: '/staff/incidents-complaints', icon: AlertTriangle, label: 'Incidents & Complaints' }, { path: '/staff/upsells', icon: TrendingUp, label: 'Upsell Management' }, { path: '/staff/advanced-rooms', icon: Wrench, label: 'Room Management' }, { path: '/staff/chats', icon: MessageCircle, label: 'Chat Support' }, { path: '/staff/reports', icon: BarChart3, label: 'Reports' }, { path: '/staff/profile', icon: Users, label: 'My Profile' }, ]; const isActive = (path: string) => { if (location.pathname === path) return true; return location.pathname.startsWith(`${path}/`); }; return ( <> {} {isMobile && ( )} {} {isMobile && isMobileOpen && (
)} {} ); }; export default SidebarStaff;