import React, { useState, useEffect } from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { LayoutDashboard, Users, Settings, FileText, BarChart3, Globe, ChevronLeft, ChevronRight, LogIn, LogOut, Menu, X, Award, User, Workflow, CheckSquare, Bell, UserCheck, Hotel, Tag, Package, Shield, Mail, TrendingUp, Building2, Crown, Star, AlertCircle, FileCheck, ClipboardCheck, CheckCircle2, Download, Webhook, Key, HardDrive, Activity, Calendar, Boxes, Monitor, CreditCard, MessageSquare } from 'lucide-react'; import useAuthStore from '../../store/useAuthStore'; import { useResponsive } from '../../hooks'; import { logger } from '../utils/logger'; interface SidebarAdminProps { isCollapsed?: boolean; onToggle?: () => void; } interface MenuGroup { title: string; icon?: React.ComponentType<{ className?: string }>; items: Array<{ path: string; icon: React.ComponentType<{ className?: string }>; label: string; }>; } const SidebarAdmin: 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 { 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 menuGroups: MenuGroup[] = [ { title: 'Overview', icon: LayoutDashboard, items: [ { path: '/admin/dashboard', icon: LayoutDashboard, label: 'Dashboard' }, ] }, { title: 'Operations', icon: Building2, items: [ { path: '/admin/reception', icon: LogIn, label: 'Reception' }, { path: '/admin/advanced-rooms', icon: Hotel, label: 'Rooms & Housekeeping' }, { path: '/admin/services', icon: Activity, label: 'Services' }, { path: '/admin/inventory', icon: Boxes, label: 'Inventory' }, { path: '/admin/shifts', icon: Calendar, label: 'Staff Shifts' }, ] }, { title: 'Bookings & Finance', icon: TrendingUp, items: [ { path: '/admin/bookings', icon: Calendar, label: 'All Bookings' }, { path: '/admin/payments', icon: CreditCard, label: 'Payments' }, { path: '/admin/invoices', icon: FileText, label: 'Invoices' }, { path: '/admin/promotions', icon: Tag, label: 'Promotions' }, { path: '/admin/financial-audit', icon: FileCheck, label: 'Financial Audit' }, ] }, { title: 'Analytics', icon: BarChart3, items: [ { path: '/admin/analytics', icon: BarChart3, label: 'Reports & Analytics' }, ] }, { title: 'Users & Guests', icon: Users, items: [ { path: '/admin/users', icon: Users, label: 'Users' }, { path: '/admin/guest-profiles', icon: User, label: 'Guest Profiles' }, { path: '/admin/group-bookings', icon: UserCheck, label: 'Group Bookings' }, { path: '/admin/loyalty', icon: Award, label: 'Loyalty Program' }, { path: '/admin/complaints', icon: AlertCircle, label: 'Complaints' }, ] }, { title: 'Products & Pricing', icon: Tag, items: [ { path: '/admin/rate-plans', icon: Tag, label: 'Rate Plans' }, { path: '/admin/packages', icon: Package, label: 'Packages' }, ] }, { title: 'Marketing', icon: Mail, items: [ { path: '/admin/email-campaigns', icon: Mail, label: 'Email Campaigns' }, ] }, { title: 'Communication', icon: MessageSquare, items: [ { path: '/admin/team-chat', icon: MessageSquare, label: 'Team Chat' }, ] }, { title: 'Content Management', icon: Globe, items: [ { path: '/admin/page-content', icon: Globe, label: 'Page Content' }, { path: '/admin/blog', icon: FileText, label: 'Blog Management' }, { path: '/admin/reviews', icon: Star, label: 'Reviews' }, ] }, { title: 'System', icon: Settings, items: [ { path: '/admin/security', icon: Shield, label: 'Security' }, { path: '/admin/tasks', icon: CheckSquare, label: 'Tasks' }, { path: '/admin/workflows', icon: Workflow, label: 'Workflows' }, { path: '/admin/notifications', icon: Bell, label: 'Notifications' }, { path: '/admin/settings', icon: Settings, label: 'Settings' }, { path: '/admin/approvals', icon: CheckCircle2, label: 'Approvals' }, { path: '/admin/gdpr', icon: Download, label: 'GDPR & Compliance' }, { path: '/admin/webhooks', icon: Webhook, label: 'Webhooks' }, { path: '/admin/api-keys', icon: Key, label: 'API Keys' }, { path: '/admin/backups', icon: HardDrive, label: 'Backups' }, ] }, { title: 'Account', icon: User, items: [ { path: '/admin/profile', icon: User, label: 'My Profile' }, { path: '/admin/sessions', icon: Monitor, label: 'Sessions' }, ] }, ]; const isActive = (path: string) => { if (location.pathname === path) return true; if (path === '/admin/settings' || path === '/admin/analytics' || path === '/admin/reception' || path === '/admin/advanced-rooms' || path === '/admin/page-content' || path === '/admin/loyalty') { return location.pathname === path; } if (path === '/admin/reception' || path === '/admin/advanced-rooms') { return location.pathname === path || location.pathname.startsWith(`${path}/`); } return location.pathname.startsWith(`${path}/`); }; return ( <> {/* Mobile Menu Button - Always visible on mobile screens */} {/* Mobile Overlay */} {isMobileOpen && (
)} ); }; export default SidebarAdmin;