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 } from 'lucide-react'; import useAuthStore from '../../store/useAuthStore'; import { useChatNotifications } from '../../contexts/ChatNotificationContext'; import { useResponsive } from '../../hooks'; 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, isTablet, isDesktop } = useResponsive(); const handleLogout = async () => { try { await logout(); navigate('/'); if (isMobile) { setIsMobileOpen(false); } } catch (error) { console.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/advanced-rooms', icon: Wrench, label: 'Room Management' }, { path: '/staff/chats', icon: MessageCircle, label: 'Chat Support' }, { path: '/staff/reports', icon: BarChart3, label: 'Reports' }, ]; const isActive = (path: string) => { if (location.pathname === path) return true; return location.pathname.startsWith(`${path}/`); }; return ( <> {} {isMobile && ( )} {} {isMobile && isMobileOpen && (
)} {} ); }; export default SidebarStaff;