import { MenuModal } from '../types/layout';
import { UserRole } from '@/types/auth';
import { useAuth } from '../contexts/AuthContext';
import AppSubMenu from './AppSubMenu';
import { useMemo } from 'react';

const AppMenu = () => {
    const { user, hasRole, hasPermission, isAuthenticated } = useAuth();

    // Menu basé sur les API endpoints réellement disponibles dans le backend

    const canAccess = (requiredRoles: UserRole[], requiredPermissions?: string[]) => {
        if (!isAuthenticated || !user) return false;

        // Vérifier les rôles requis
        if (requiredRoles && requiredRoles.length > 0) {
            const hasRequiredRole = requiredRoles.some(role => hasRole(role));
            if (!hasRequiredRole) return false;
        }

        // Vérifier les permissions requises
        if (requiredPermissions && requiredPermissions.length > 0) {
            const hasRequiredPermission = requiredPermissions.some(permission => hasPermission(permission));
            if (!hasRequiredPermission) return false;
        }

        return true;
    };

    const filterMenuItems = (items: MenuModal[]): MenuModal[] => {
        return items.filter(item => {
            if (item.separator) return true;
            if (!item.requiredRoles && !item.requiredPermissions) return true;
            
            const hasAccess = canAccess(item.requiredRoles || [], item.requiredPermissions);
            
            if (hasAccess && item.items) {
                item.items = filterMenuItems(item.items);
                return item.items.length > 0;
            }
            
            return hasAccess;
        });
    };

    const baseModel: MenuModal[] = [
        {
            label: 'Tableau de Bord',
            icon: 'pi pi-home',
            items: [
                {
                    label: 'Vue d\'ensemble',
                    icon: 'pi pi-fw pi-chart-line',
                    to: '/dashboard',
                    requiredRoles: [UserRole.ADMIN, UserRole.MANAGER]
                },
                {
                    label: 'Dashboard Gestionnaire',
                    icon: 'pi pi-fw pi-users',
                    to: '/gestionnaire/dashboard',
                    requiredRoles: [UserRole.GESTIONNAIRE_PROJET]
                },
                {
                    label: 'Mon Espace Client',
                    icon: 'pi pi-fw pi-user',
                    to: '/client/dashboard',
                    requiredRoles: [UserRole.CLIENT]
                },
                {
                    label: 'Dashboard Chantiers',
                    icon: 'pi pi-fw pi-building',
                    to: '/dashboard/chantiers',
                    requiredRoles: [UserRole.ADMIN, UserRole.MANAGER, UserRole.CHEF_CHANTIER]
                },
                {
                    label: 'Dashboard Maintenance',
                    icon: 'pi pi-fw pi-wrench',
                    to: '/dashboard/maintenance',
                    requiredRoles: [UserRole.ADMIN, UserRole.MANAGER]
                },
                {
                    label: 'Dashboard Ressources',
                    icon: 'pi pi-fw pi-users',
                    to: '/dashboard/ressources'
                },
                {
                    label: 'Dashboard Planning',
                    icon: 'pi pi-fw pi-calendar',
                    to: '/dashboard/planning'
                },
                {
                    label: 'Alertes & KPI',
                    icon: 'pi pi-fw pi-exclamation-triangle',
                    to: '/dashboard/alertes'
                },
                {
                    label: 'Résumé Quotidien',
                    icon: 'pi pi-fw pi-file-o',
                    to: '/dashboard/resume-quotidien'
                }
            ]
        },
        { separator: true },
        {
            label: 'Gestion BTP',
            icon: 'pi pi-building',
            items: [
                {
                    label: 'Chantiers',
                    icon: 'pi pi-fw pi-map',
                    items: [
                        {
                            label: 'Tous les chantiers',
                            icon: 'pi pi-fw pi-list',
                            to: '/chantiers'
                        },
                        {
                            label: 'En cours',
                            icon: 'pi pi-fw pi-play-circle',
                            to: '/chantiers/en-cours'
                        },
                        {
                            label: 'Planifiés',
                            icon: 'pi pi-fw pi-calendar',
                            to: '/chantiers/planifies'
                        },
                        {
                            label: 'Terminés',
                            icon: 'pi pi-fw pi-check-circle',
                            to: '/chantiers/termines'
                        },
                        {
                            label: 'Statistiques',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/chantiers/stats'
                        },
                        {
                            label: 'Exécution granulaire',
                            icon: 'pi pi-fw pi-check-square',
                            to: '/chantiers/execution-granulaire',
                            requiredRoles: [UserRole.ADMIN, UserRole.MANAGER, UserRole.CHEF_CHANTIER]
                        },
                        {
                            label: 'Nouveau chantier',
                            icon: 'pi pi-fw pi-plus',
                            to: '/chantiers/nouveau'
                        }
                    ]
                },
                {
                    label: 'Clients',
                    icon: 'pi pi-fw pi-users',
                    items: [
                        {
                            label: 'Liste des clients',
                            icon: 'pi pi-fw pi-list',
                            to: '/clients'
                        },
                        {
                            label: 'Recherche clients',
                            icon: 'pi pi-fw pi-search',
                            to: '/clients/recherche'
                        },
                        {
                            label: 'Nouveau client',
                            icon: 'pi pi-fw pi-user-plus',
                            to: '/clients/nouveau'
                        }
                    ]
                },
                {
                    label: 'Devis',
                    icon: 'pi pi-fw pi-file-edit',
                    items: [
                        {
                            label: 'Tous les devis',
                            icon: 'pi pi-fw pi-list',
                            to: '/devis'
                        },
                        {
                            label: 'En attente',
                            icon: 'pi pi-fw pi-clock',
                            to: '/devis/en-attente'
                        },
                        {
                            label: 'Acceptés',
                            icon: 'pi pi-fw pi-check',
                            to: '/devis/acceptes'
                        },
                        {
                            label: 'Expirant bientôt',
                            icon: 'pi pi-fw pi-exclamation-triangle',
                            to: '/devis/expiring'
                        },
                        {
                            label: 'Recherche par dates',
                            icon: 'pi pi-fw pi-search',
                            to: '/devis/search'
                        },
                        {
                            label: 'Nouveau devis',
                            icon: 'pi pi-fw pi-plus',
                            to: '/devis/nouveau'
                        }
                    ]
                },
                {
                    label: 'Factures',
                    icon: 'pi pi-fw pi-receipt',
                    items: [
                        {
                            label: 'Toutes les factures',
                            icon: 'pi pi-fw pi-list',
                            to: '/factures'
                        },
                        {
                            label: 'Échues',
                            icon: 'pi pi-fw pi-exclamation-circle',
                            to: '/factures/echues'
                        },
                        {
                            label: 'Proches échéance',
                            icon: 'pi pi-fw pi-clock',
                            to: '/factures/proches-echeance'
                        },
                        {
                            label: 'Par période',
                            icon: 'pi pi-fw pi-calendar',
                            to: '/factures/date-range'
                        },
                        {
                            label: 'Chiffre d\'affaires',
                            icon: 'pi pi-fw pi-dollar',
                            to: '/factures/chiffre-affaires'
                        },
                        {
                            label: 'Nouvelle facture',
                            icon: 'pi pi-fw pi-plus',
                            to: '/factures/nouvelle'
                        }
                    ]
                }
            ]
        },
        { separator: true },
        {
            label: 'Configuration & Templates',
            icon: 'pi pi-cog',
            items: [
                {
                    label: 'Templates de Tâches',
                    icon: 'pi pi-fw pi-list-check',
                    to: '/templates/taches',
                    requiredRoles: [UserRole.ADMIN, UserRole.MANAGER]
                }
            ]
        },
        { separator: true },
        {
            label: 'Gestion Budgétaire',
            icon: 'pi pi-calculator',
            items: [
                {
                    label: 'Planification Budgétaire',
                    icon: 'pi pi-fw pi-chart-pie',
                    items: [
                        {
                            label: 'Vue d\'ensemble budgets',
                            icon: 'pi pi-fw pi-eye',
                            to: '/budget/planification'
                        },
                        {
                            label: 'Budgets par chantier',
                            icon: 'pi pi-fw pi-building',
                            to: '/budget/planification/chantiers'
                        },
                        {
                            label: 'Budgets par phase',
                            icon: 'pi pi-fw pi-sitemap',
                            to: '/budget/planification/phases'
                        },
                        {
                            label: 'Modèles de budget',
                            icon: 'pi pi-fw pi-clone',
                            to: '/budget/planification/modeles'
                        },
                        {
                            label: 'Nouvelle planification',
                            icon: 'pi pi-fw pi-plus',
                            to: '/budget/planification/nouveau'
                        }
                    ]
                },
                {
                    label: 'Suivi des Dépenses',
                    icon: 'pi pi-fw pi-chart-line',
                    items: [
                        {
                            label: 'Tableau de bord dépenses',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/budget/suivi'
                        },
                        {
                            label: 'Dépenses par chantier',
                            icon: 'pi pi-fw pi-building',
                            to: '/budget/suivi/chantiers'
                        },
                        {
                            label: 'Dépenses par catégorie',
                            icon: 'pi pi-fw pi-tags',
                            to: '/budget/suivi/categories'
                        },
                        {
                            label: 'Analyse des écarts',
                            icon: 'pi pi-fw pi-exclamation-triangle',
                            to: '/budget/suivi/ecarts'
                        },
                        {
                            label: 'Alertes budgétaires',
                            icon: 'pi pi-fw pi-bell',
                            to: '/budget/suivi/alertes'
                        },
                        {
                            label: 'Saisir nouvelle dépense',
                            icon: 'pi pi-fw pi-plus',
                            to: '/budget/suivi/nouvelle-depense'
                        }
                    ]
                },
                {
                    label: 'Analyses Budgétaires',
                    icon: 'pi pi-fw pi-chart-bar',
                    items: [
                        {
                            label: 'Rentabilité projets',
                            icon: 'pi pi-fw pi-percentage',
                            to: '/budget/analyses/rentabilite'
                        },
                        {
                            label: 'Évolution des coûts',
                            icon: 'pi pi-fw pi-chart-line',
                            to: '/budget/analyses/evolution-couts'
                        },
                        {
                            label: 'Prévisions budgétaires',
                            icon: 'pi pi-fw pi-forward',
                            to: '/budget/analyses/previsions'
                        },
                        {
                            label: 'Comparaisons historiques',
                            icon: 'pi pi-fw pi-history',
                            to: '/budget/analyses/historique'
                        },
                        {
                            label: 'Export rapports budget',
                            icon: 'pi pi-fw pi-file-excel',
                            to: '/budget/analyses/export'
                        }
                    ]
                }
            ]
        },
        { separator: true },
        {
            label: 'Ressources Humaines',
            icon: 'pi pi-users',
            items: [
                {
                    label: 'Employés',
                    icon: 'pi pi-fw pi-user',
                    items: [
                        {
                            label: 'Liste des employés',
                            icon: 'pi pi-fw pi-list',
                            to: '/employes'
                        },
                        {
                            label: 'Employés actifs',
                            icon: 'pi pi-fw pi-check-circle',
                            to: '/employes/actifs'
                        },
                        {
                            label: 'Employés disponibles',
                            icon: 'pi pi-fw pi-calendar-check',
                            to: '/employes/disponibles'
                        },
                        {
                            label: 'Statistiques employés',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/employes/stats'
                        },
                        {
                            label: 'Nouvel employé',
                            icon: 'pi pi-fw pi-user-plus',
                            to: '/employes/nouveau'
                        }
                    ]
                },
                {
                    label: 'Équipes',
                    icon: 'pi pi-fw pi-users',
                    items: [
                        {
                            label: 'Toutes les équipes',
                            icon: 'pi pi-fw pi-list',
                            to: '/equipes'
                        },
                        {
                            label: 'Équipes disponibles',
                            icon: 'pi pi-fw pi-check-circle',
                            to: '/equipes/disponibles'
                        },
                        {
                            label: 'Spécialités équipes',
                            icon: 'pi pi-fw pi-star',
                            to: '/equipes/specialites'
                        },
                        {
                            label: 'Équipe optimale',
                            icon: 'pi pi-fw pi-search',
                            to: '/equipes/optimal'
                        },
                        {
                            label: 'Statistiques équipes',
                            icon: 'pi pi-fw pi-chart-line',
                            to: '/equipes/stats'
                        },
                        {
                            label: 'Nouvelle équipe',
                            icon: 'pi pi-fw pi-plus',
                            to: '/equipes/nouvelle'
                        }
                    ]
                },
                {
                    label: 'Disponibilités',
                    icon: 'pi pi-fw pi-calendar-times',
                    items: [
                        {
                            label: 'Toutes les disponibilités',
                            icon: 'pi pi-fw pi-list',
                            to: '/disponibilites'
                        },
                        {
                            label: 'Disponibilités actuelles',
                            icon: 'pi pi-fw pi-calendar',
                            to: '/disponibilites/actuelles'
                        },
                        {
                            label: 'Disponibilités futures',
                            icon: 'pi pi-fw pi-forward',
                            to: '/disponibilites/futures'
                        },
                        {
                            label: 'Demandes en attente',
                            icon: 'pi pi-fw pi-clock',
                            to: '/disponibilites/en-attente'
                        },
                        {
                            label: 'Recherche par période',
                            icon: 'pi pi-fw pi-search',
                            to: '/disponibilites/periode'
                        },
                        {
                            label: 'Conflits de planning',
                            icon: 'pi pi-fw pi-exclamation-triangle',
                            to: '/disponibilites/conflits'
                        },
                        {
                            label: 'Statistiques',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/disponibilites/statistiques'
                        }
                    ]
                }
            ]
        },
        { separator: true },
        {
            label: 'Matériel & Maintenance',
            icon: 'pi pi-wrench',
            items: [
                {
                    label: 'Parc Matériel',
                    icon: 'pi pi-fw pi-cog',
                    items: [
                        {
                            label: 'Inventaire matériel',
                            icon: 'pi pi-fw pi-list',
                            to: '/materiels'
                        },
                        {
                            label: 'Matériel disponible',
                            icon: 'pi pi-fw pi-check-circle',
                            to: '/materiels/disponibles'
                        },
                        {
                            label: 'Maintenance prévue',
                            icon: 'pi pi-fw pi-clock',
                            to: '/materiels/maintenance-prevue'
                        },
                        {
                            label: 'Par type de matériel',
                            icon: 'pi pi-fw pi-sitemap',
                            to: '/materiels/by-type'
                        },
                        {
                            label: 'Recherche matériel',
                            icon: 'pi pi-fw pi-search',
                            to: '/materiels/search'
                        },
                        {
                            label: 'Statistiques & Valeur',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/materiels/stats'
                        },
                        {
                            label: 'Nouveau matériel',
                            icon: 'pi pi-fw pi-plus',
                            to: '/materiels/nouveau'
                        }
                    ]
                },
                {
                    label: 'Maintenance',
                    icon: 'pi pi-fw pi-wrench',
                    items: [
                        {
                            label: 'Toutes les maintenances',
                            icon: 'pi pi-fw pi-list',
                            to: '/maintenances'
                        },
                        {
                            label: 'Planifiées',
                            icon: 'pi pi-fw pi-calendar',
                            to: '/maintenances/planifiees'
                        },
                        {
                            label: 'En cours',
                            icon: 'pi pi-fw pi-play-circle',
                            to: '/maintenances/en-cours'
                        },
                        {
                            label: 'Terminées',
                            icon: 'pi pi-fw pi-check-circle',
                            to: '/maintenances/terminees'
                        },
                        {
                            label: 'En retard',
                            icon: 'pi pi-fw pi-exclamation-triangle',
                            to: '/maintenances/en-retard'
                        },
                        {
                            label: 'Prochaines maintenances',
                            icon: 'pi pi-fw pi-forward',
                            to: '/maintenances/prochaines'
                        },
                        {
                            label: 'Préventives',
                            icon: 'pi pi-fw pi-shield',
                            to: '/maintenances/preventives'
                        },
                        {
                            label: 'Correctives',
                            icon: 'pi pi-fw pi-bolt',
                            to: '/maintenances/correctives'
                        },
                        {
                            label: 'Matériel attention requise',
                            icon: 'pi pi-fw pi-eye',
                            to: '/maintenances/attention-requise'
                        },
                        {
                            label: 'Coûts maintenance',
                            icon: 'pi pi-fw pi-dollar',
                            to: '/maintenances/cout-total-periode'
                        },
                        {
                            label: 'Statistiques détaillées',
                            icon: 'pi pi-fw pi-chart-line',
                            to: '/maintenances/statistiques'
                        },
                        {
                            label: 'Nouvelle maintenance',
                            icon: 'pi pi-fw pi-plus',
                            to: '/maintenances/nouvelle'
                        }
                    ]
                }
            ]
        },
        { separator: true },
        {
            label: 'Planning & Organisation',
            icon: 'pi pi-calendar',
            items: [
                {
                    label: 'Vue Planning',
                    icon: 'pi pi-fw pi-calendar',
                    to: '/planning'
                },
                {
                    label: 'Planning Hebdomadaire',
                    icon: 'pi pi-fw pi-calendar-plus',
                    to: '/planning/week'
                },
                {
                    label: 'Planning Mensuel',
                    icon: 'pi pi-fw pi-th',
                    to: '/planning/month'
                },
                {
                    label: 'Événements Planning',
                    icon: 'pi pi-fw pi-list',
                    to: '/planning/events'
                },
                {
                    label: 'Conflits de Ressources',
                    icon: 'pi pi-fw pi-exclamation-triangle',
                    to: '/planning/conflicts'
                },
                {
                    label: 'Vérifier Disponibilité',
                    icon: 'pi pi-fw pi-search',
                    to: '/planning/check-availability'
                },
                {
                    label: 'Statistiques Planning',
                    icon: 'pi pi-fw pi-chart-bar',
                    to: '/planning/stats'
                }
            ]
        },
        { separator: true },
        {
            label: 'Documents & Photos',
            icon: 'pi pi-folder',
            items: [
                {
                    label: 'Gestion Documents',
                    icon: 'pi pi-fw pi-file',
                    items: [
                        {
                            label: 'Tous les documents',
                            icon: 'pi pi-fw pi-list',
                            to: '/documents'
                        },
                        {
                            label: 'Documents images',
                            icon: 'pi pi-fw pi-image',
                            to: '/documents/images'
                        },
                        {
                            label: 'Documents PDF',
                            icon: 'pi pi-fw pi-file-pdf',
                            to: '/documents/pdfs'
                        },
                        {
                            label: 'Documents publics',
                            icon: 'pi pi-fw pi-globe',
                            to: '/documents/publics'
                        },
                        {
                            label: 'Documents récents',
                            icon: 'pi pi-fw pi-clock',
                            to: '/documents/recents'
                        },
                        {
                            label: 'Documents orphelins',
                            icon: 'pi pi-fw pi-question-circle',
                            to: '/documents/orphelins'
                        },
                        {
                            label: 'Statistiques documents',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/documents/statistiques'
                        },
                        {
                            label: 'Upload document',
                            icon: 'pi pi-fw pi-upload',
                            to: '/documents/upload'
                        }
                    ]
                },
                {
                    label: 'Photos Chantiers',
                    icon: 'pi pi-fw pi-camera',
                    items: [
                        {
                            label: 'Toutes les photos',
                            icon: 'pi pi-fw pi-images',
                            to: '/photos'
                        },
                        {
                            label: 'Photos récentes',
                            icon: 'pi pi-fw pi-clock',
                            to: '/photos/recentes'
                        },
                        {
                            label: 'Par chantier',
                            icon: 'pi pi-fw pi-building',
                            to: '/photos/par-chantier'
                        },
                        {
                            label: 'Par employé',
                            icon: 'pi pi-fw pi-user',
                            to: '/photos/par-employe'
                        },
                        {
                            label: 'Galeries chantiers',
                            icon: 'pi pi-fw pi-th-large',
                            to: '/photos/galeries'
                        },
                        {
                            label: 'Statistiques photos',
                            icon: 'pi pi-fw pi-chart-line',
                            to: '/photos/statistiques'
                        },
                        {
                            label: 'Upload photos',
                            icon: 'pi pi-fw pi-upload',
                            to: '/photos/upload'
                        }
                    ]
                }
            ]
        },
        { separator: true },
        {
            label: 'Communication',
            icon: 'pi pi-comments',
            items: [
                {
                    label: 'Messagerie',
                    icon: 'pi pi-fw pi-envelope',
                    items: [
                        {
                            label: 'Boîte de réception',
                            icon: 'pi pi-fw pi-inbox',
                            to: '/messages/boite-reception'
                        },
                        {
                            label: 'Boîte d\'envoi',
                            icon: 'pi pi-fw pi-send',
                            to: '/messages/boite-envoi'
                        },
                        {
                            label: 'Messages non lus',
                            icon: 'pi pi-fw pi-exclamation-circle',
                            to: '/messages/non-lus'
                        },
                        {
                            label: 'Messages importants',
                            icon: 'pi pi-fw pi-star',
                            to: '/messages/importants'
                        },
                        {
                            label: 'Messages archivés',
                            icon: 'pi pi-fw pi-archive',
                            to: '/messages/archives'
                        },
                        {
                            label: 'Conversations',
                            icon: 'pi pi-fw pi-comments',
                            to: '/messages/conversations'
                        },
                        {
                            label: 'Recherche messages',
                            icon: 'pi pi-fw pi-search',
                            to: '/messages/recherche'
                        },
                        {
                            label: 'Statistiques messagerie',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/messages/statistiques'
                        },
                        {
                            label: 'Nouveau message',
                            icon: 'pi pi-fw pi-plus',
                            to: '/messages/nouveau'
                        },
                        {
                            label: 'Diffuser message',
                            icon: 'pi pi-fw pi-megaphone',
                            to: '/messages/diffuser'
                        }
                    ]
                },
                {
                    label: 'Notifications',
                    icon: 'pi pi-fw pi-bell',
                    items: [
                        {
                            label: 'Toutes les notifications',
                            icon: 'pi pi-fw pi-list',
                            to: '/notifications'
                        },
                        {
                            label: 'Notifications non lues',
                            icon: 'pi pi-fw pi-exclamation-circle',
                            to: '/notifications/non-lues'
                        },
                        {
                            label: 'Notifications récentes',
                            icon: 'pi pi-fw pi-clock',
                            to: '/notifications/recentes'
                        },
                        {
                            label: 'Tableau de bord',
                            icon: 'pi pi-fw pi-chart-line',
                            to: '/notifications/tableau-bord'
                        },
                        {
                            label: 'Statistiques',
                            icon: 'pi pi-fw pi-chart-bar',
                            to: '/notifications/statistiques'
                        },
                        {
                            label: 'Diffuser notification',
                            icon: 'pi pi-fw pi-megaphone',
                            to: '/notifications/broadcast'
                        },
                        {
                            label: 'Notifications automatiques',
                            icon: 'pi pi-fw pi-cog',
                            to: '/notifications/automatiques'
                        }
                    ]
                }
            ]
        },
        { separator: true },
        {
            label: 'Rapports & Analyses',
            icon: 'pi pi-chart-bar',
            items: [
                {
                    label: 'Rapports Chantiers',
                    icon: 'pi pi-fw pi-building',
                    to: '/reports/chantiers'
                },
                {
                    label: 'Rapport Maintenance',
                    icon: 'pi pi-fw pi-wrench',
                    to: '/reports/maintenance'
                },
                {
                    label: 'Rapport RH',
                    icon: 'pi pi-fw pi-users',
                    to: '/reports/ressources-humaines'
                },
                {
                    label: 'Rapport Financier',
                    icon: 'pi pi-fw pi-dollar',
                    to: '/reports/financier'
                },
                {
                    label: 'Export CSV Chantiers',
                    icon: 'pi pi-fw pi-file-excel',
                    to: '/reports/export/csv/chantiers'
                },
                {
                    label: 'Export CSV Maintenance',
                    icon: 'pi pi-fw pi-file-excel',
                    to: '/reports/export/csv/maintenance'
                }
            ]
        },
        { separator: true },
        {
            label: 'Admin & Utilisateurs',
            icon: 'pi pi-shield',
            requiredRoles: [UserRole.ADMIN, UserRole.MANAGER],
            items: [
                {
                    label: 'Gestion Utilisateurs',
                    icon: 'pi pi-fw pi-users',
                    requiredRoles: [UserRole.ADMIN, UserRole.MANAGER],
                    items: [
                        {
                            label: 'Tous les utilisateurs',
                            icon: 'pi pi-fw pi-list',
                            to: '/admin/utilisateurs',
                            requiredRoles: [UserRole.ADMIN, UserRole.MANAGER]
                        },
                        {
                            label: 'Demandes d\'accès',
                            icon: 'pi pi-fw pi-clock',
                            to: '/admin/demandes-acces',
                            requiredRoles: [UserRole.ADMIN, UserRole.MANAGER]
                        },
                        {
                            label: 'Attribution Gestionnaires',
                            icon: 'pi pi-fw pi-sitemap',
                            to: '/admin/attributions',
                            requiredRoles: [UserRole.ADMIN, UserRole.MANAGER]
                        },
                        {
                            label: 'Gestion des rôles',
                            icon: 'pi pi-fw pi-shield',
                            to: '/admin/roles',
                            requiredRoles: [UserRole.ADMIN]
                        }
                    ]
                },
                {
                    label: 'Mon Profil',
                    icon: 'pi pi-fw pi-user',
                    items: [
                        {
                            label: 'Voir mon profil',
                            icon: 'pi pi-fw pi-id-card',
                            to: '/auth/profile'
                        },
                        {
                            label: 'Modifier profil',
                            icon: 'pi pi-fw pi-user-edit',
                            to: '/auth/profile/edit'
                        },
                        {
                            label: 'Changer mot de passe',
                            icon: 'pi pi-fw pi-key',
                            to: '/auth/change-password'
                        }
                    ]
                }
            ]
        }
    ];

    const model = useMemo(() => filterMenuItems(baseModel), [baseModel]);

    return <AppSubMenu model={model} />;
};

export default AppMenu;