<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:fr="http://primefaces.org/freya">

<div class="menu-wrapper">
    <div class="sidebar-logo">
        <a href="dashboard.xhtml" class="sidebar-logo-link">
            <h:graphicImage value="#{request.contextPath}/resources/freya-layout/images/unionflow-logo.png"
                            alt="UnionFlow"
                            styleClass="unionflow-sidebar-icon" />
            <span class="unionflow-sidebar-text">
                <span class="unionflow-sidebar-name">UNIONFLOW</span>
                <span class="unionflow-sidebar-slogan">Connecter · Unir · Avancer</span>
            </span>
            <span class="unionflow-sidebar-version">v1.0</span>
        </a>
        <a href="#" class="sidebar-pin" title="Toggle Menu">
            <span class="pin"></span>
        </a>
    </div>
    <div class="layout-menu-container">
        <h:form id="menuform">
            <fr:menu widgetVar="FreyaMenuWidget">

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- TABLEAU DE BORD                                         -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:menuitem id="m_dashboard" value="Tableau de Bord" icon="pi pi-home" outcome="#{paths.dashboard}" />

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- SUPER ADMINISTRATION (SUPER_ADMIN uniquement)           -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_super_admin" label="Super Administration" icon="pi pi-shield" rendered="#{menuBean.superAdminMenuVisible}">
                    <p:menuitem id="m_super_dashboard" value="Dashboard Super-Admin" icon="pi pi-chart-bar" outcome="#{paths.superAdminDashboard}" />
                    <p:menuitem id="m_roles" value="Rôles Applicatifs" icon="pi pi-key" outcome="#{paths.superAdminRolesGestion}" />
                    <p:menuitem id="m_audit" value="Journal d'Audit" icon="pi pi-file-o" outcome="#{paths.adminAuditJournal}" />
                    <p:menuitem id="m_logs_systeme" value="Logs Système" icon="pi pi-list" outcome="#{paths.adminLogsSysteme}" />
                    <p:menuitem id="m_sauvegardes" value="Sauvegardes" icon="pi pi-save" outcome="#{paths.adminSauvegarde}" />
                    <p:menuitem id="m_config_systeme" value="Configuration Système" icon="pi pi-cog" outcome="#{paths.superAdminConfigurationSysteme}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- ORGANISATIONS                                           -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_organisations" label="Organisations" icon="pi pi-building" rendered="#{menuBean.superAdmin}">
                    <p:menuitem id="m_liste_organisations" value="Liste des Organisations" icon="pi pi-list" outcome="#{paths.organisationListe}" />
                    <p:menuitem id="m_nouvelle_organisation" value="Nouvelle Organisation" icon="pi pi-plus" outcome="#{paths.organisationNouvelle}" />
                    <p:menuitem id="m_statistiques_orga" value="Statistiques" icon="pi pi-chart-bar" outcome="#{paths.organisationStatistiques}" />
                    <p:menuitem id="m_types_organisations" value="Types d'Organisation" icon="pi pi-tags" outcome="#{paths.superAdminTypesOrganisations}" />
                </p:submenu>

                <p:submenu id="m_mon_organisation" label="Mon Organisation" icon="pi pi-building" rendered="#{menuBean.adminOrganisation and not menuBean.superAdmin}">
                    <p:menuitem id="m_detail_organisation" value="Détail &amp; Paramètres" icon="pi pi-building"
                                outcome="#{paths.organisationDetail}">
                        <f:param name="id" value="#{userSession.activeOrganisationId}" />
                    </p:menuitem>
                    <p:menuitem id="m_mon_abonnement" value="Mon Abonnement" icon="pi pi-credit-card"
                                outcome="#{paths.souscriptionDashboard}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- MEMBRES                                                 -->
                <!-- Un seul sous-menu, items conditionnels par rôle         -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_membres" label="Membres" icon="pi pi-users" rendered="#{menuBean.annuaireMembresVisible}">
                    <p:menuitem id="m_liste_membres" value="Annuaire des Membres" icon="pi pi-list" outcome="#{paths.membreListe}" />
                    <p:menuitem id="m_recherche_membres" value="Rechercher un Membre" icon="pi pi-search" outcome="#{paths.membreRecherche}" />
                    <p:menuitem id="m_inscription" value="Nouvelle Inscription" icon="pi pi-user-plus" outcome="#{paths.membreInscription}" rendered="#{menuBean.gestionMembresMenuVisible}" />
                    <p:menuitem id="m_validation_membres" value="Validation Inscriptions" icon="pi pi-check-circle" outcome="#{paths.membreValidation}" rendered="#{menuBean.gestionMembresMenuVisible}" />
                    <p:menuitem id="m_import_membres" value="Import en Masse" icon="pi pi-upload" outcome="#{paths.membreImport}" rendered="#{menuBean.gestionMembresMenuVisible}" />
                    <p:menuitem id="m_export_membres" value="Export Membres" icon="pi pi-download" outcome="#{paths.membreExport}" rendered="#{menuBean.gestionMembresMenuVisible}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- ADHÉSIONS                                               -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_adhesions" label="Adhésions" icon="pi pi-bookmark" rendered="#{menuBean.adhesionsMenuVisible}">
                    <p:menuitem id="m_demande_adhesion" value="Nouvelle Demande" icon="pi pi-plus-circle" outcome="#{paths.adhesionDemande}" />
                    <p:menuitem id="m_liste_adhesions" value="Toutes les Adhésions" icon="pi pi-list" outcome="#{paths.adhesionListe}" />
                    <p:menuitem id="m_validation_adhesion" value="Validation des Demandes" icon="pi pi-check-circle" outcome="#{paths.adhesionValidation}" rendered="#{menuBean.validationAdhesionVisible}" />
                    <p:menuitem id="m_renouvellement" value="Renouvellements" icon="pi pi-refresh" outcome="#{paths.adhesionRenouvellement}" />
                    <p:menuitem id="m_historique_adhesions" value="Historique" icon="pi pi-history" outcome="#{paths.adhesionHistorique}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- MES FINANCES (perso — tous les membres)                 -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_mes_finances" label="Mes Finances" icon="pi pi-wallet" rendered="#{menuBean.mesFinancesMenuVisible}">
                    <p:menuitem id="m_mes_cotisations" value="Mes Cotisations" icon="pi pi-credit-card" outcome="#{paths.membreCotisations}" />
                    <p:menuitem id="m_payer_cotisations" value="Payer mes Cotisations" icon="pi pi-dollar" outcome="#{paths.cotisationPaiement}" />
                    <p:menuitem id="m_historique_finances" value="Historique" icon="pi pi-history" outcome="#{paths.cotisationHistorique}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- GESTION FINANCIÈRE (admin — trésorier, admin org)       -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_gestion_finances" label="Gestion Financière" icon="pi pi-dollar" rendered="#{menuBean.gestionFinancesMenuVisible}">
                    <p:menuitem id="m_gestion_cotisations" value="Gestion Cotisations" icon="pi pi-dollar" outcome="#{paths.cotisationsGestionAdmin}" />
                    <p:menuitem id="m_tresorerie" value="Trésorerie" icon="pi pi-wallet" outcome="#{paths.financeTresorerie}" />
                    <p:menuitem id="m_budgets" value="Gestion des Budgets" icon="pi pi-chart-pie" outcome="#{paths.financeBudgets}" />
                    <p:menuitem id="m_approbations_finance" value="Approbations" icon="pi pi-check-square" outcome="#{paths.financeApprobations}" />
                    <p:menuitem id="m_comptabilite" value="Comptabilité" icon="pi pi-calculator" outcome="#{paths.comptabiliteGestion}" />
                    <p:menuitem id="m_relances" value="Relances Cotisations" icon="pi pi-bell" outcome="#{paths.cotisationRelances}" />
                    <p:menuitem id="m_bilans" value="Bilans Financiers" icon="pi pi-chart-line" outcome="#{paths.financeBilans}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- CONFORMITÉ (Sprint 8 — BCEAO / ARTCI / OHADA)           -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_conformite" label="Conformité" icon="pi pi-verified" rendered="#{menuBean.conformiteDashboardVisible}">
                    <p:menuitem id="m_conformite_dashboard" value="Tableau de bord" icon="pi pi-chart-bar" outcome="#{paths.conformiteDashboard}" />
                    <p:menuitem id="m_rapports_trimestriels" value="Rapports trimestriels" icon="pi pi-file-pdf" outcome="#{paths.conformiteRapportsTrimestriels}" rendered="#{menuBean.rapportsTrimestrielsVisible}" />
                    <p:menuitem id="m_ubo" value="Bénéficiaires Effectifs" icon="pi pi-users" outcome="#{paths.conformiteBeneficiairesEffectifs}" rendered="#{menuBean.beneficiairesEffectifsVisible}" />
                    <p:menuitem id="m_audit_trail" value="Audit Trail" icon="pi pi-history" outcome="#{paths.conformiteAuditTrail}" rendered="#{menuBean.auditTrailViewerVisible}" />
                    <p:menuitem id="m_live_feed" value="Live Activity Feed" icon="pi pi-bolt" outcome="#{paths.conformiteLiveFeed}" />
                    <p:menuitem id="m_role_delegations" value="Délégations de rôles" icon="pi pi-share-alt" outcome="#{paths.adminRoleDelegations}" rendered="#{menuBean.roleDelegationsVisible}" />
                    <p:menuitem id="m_pispi_readiness" value="PI-SPI Readiness" icon="pi pi-cog" outcome="#{paths.adminPispiReadiness}" rendered="#{menuBean.pispiReadinessVisible}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- ÉPARGNE (module EPARGNE — mutuelle, coopérative)        -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_epargne" label="Épargne &amp; Crédit" icon="pi pi-wallet" rendered="#{menuBean.epargneMenuVisible}">
                    <p:menuitem id="m_epargne_comptes" value="Comptes Épargne" icon="pi pi-wallet" outcome="#{paths.epargneComptes}" />
                    <p:menuitem id="m_demandes_credit" value="Demandes de Crédit" icon="pi pi-inbox" outcome="#{paths.creditDemandes}" rendered="#{menuBean.creditMenuVisible}" />
                    <p:menuitem id="m_evaluation_credit" value="Évaluation Solvabilité" icon="pi pi-search" outcome="#{paths.creditEvaluation}" rendered="#{menuBean.creditMenuVisible}" />
                    <p:menuitem id="m_suivi_credits" value="Suivi des Crédits" icon="pi pi-eye" outcome="#{paths.creditSuivi}" rendered="#{menuBean.creditMenuVisible}" />
                    <p:menuitem id="m_remboursements" value="Remboursements" icon="pi pi-replay" outcome="#{paths.creditRemboursements}" rendered="#{menuBean.creditMenuVisible}" />
                    <p:menuitem id="m_stats_credit" value="Statistiques Crédit" icon="pi pi-chart-bar" outcome="#{paths.creditStatistiques}" rendered="#{menuBean.creditMenuVisible}" />
                </p:submenu>

                <!-- Mon Épargne (membre — visible si pas admin épargne) -->
                <p:submenu id="m_mon_epargne" label="Mon Épargne" icon="pi pi-wallet" rendered="#{menuBean.epargneMemberVisible and not menuBean.epargneMenuVisible}">
                    <p:menuitem id="m_mon_epargne_compte" value="Mon Compte Épargne" icon="pi pi-wallet" outcome="#{paths.epargneComptes}" />
                    <p:menuitem id="m_demande_pret" value="Demander un Prêt" icon="pi pi-plus" outcome="#{paths.creditDemandes}" rendered="#{menuBean.creditMemberVisible}" />
                    <p:menuitem id="m_mes_credits" value="Mes Crédits en Cours" icon="pi pi-list" outcome="#{paths.creditSuivi}" rendered="#{menuBean.creditMemberVisible}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- MODULES MÉTIER SPÉCIALISÉS (Coming Soon)                -->
                <!-- Affichés uniquement si le module est actif pour l'org   -->
                <!-- Un seul item par module → page "coming soon" à terme   -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_tontine" label="Tontine" icon="pi pi-sync" rendered="#{menuBean.tontineMenuVisible}">
                    <p:menuitem id="m_tontine_info" value="Bientôt disponible" icon="pi pi-info-circle" disabled="true" />
                </p:submenu>

                <p:submenu id="m_agricole" label="Agriculture" icon="pi pi-sun" rendered="#{menuBean.agricoleMenuVisible}">
                    <p:menuitem id="m_agricole_info" value="Bientôt disponible" icon="pi pi-info-circle" disabled="true" />
                </p:submenu>

                <p:submenu id="m_collecte" label="Collecte de Fonds" icon="pi pi-heart" rendered="#{menuBean.collecteFondsMenuVisible}">
                    <p:menuitem id="m_collecte_info" value="Bientôt disponible" icon="pi pi-info-circle" disabled="true" />
                </p:submenu>

                <p:submenu id="m_projets_ong" label="Projets ONG" icon="pi pi-globe" rendered="#{menuBean.projetOngMenuVisible}">
                    <p:menuitem id="m_projets_info" value="Bientôt disponible" icon="pi pi-info-circle" disabled="true" />
                </p:submenu>

                <p:submenu id="m_culte" label="Culte et Dons" icon="pi pi-star" rendered="#{menuBean.culteMenuVisible}">
                    <p:menuitem id="m_culte_info" value="Bientôt disponible" icon="pi pi-info-circle" disabled="true" />
                </p:submenu>

                <p:submenu id="m_votes" label="Votes et Élections" icon="pi pi-check-circle" rendered="#{menuBean.voteMenuVisible}">
                    <p:menuitem id="m_votes_info" value="Bientôt disponible" icon="pi pi-info-circle" disabled="true" />
                </p:submenu>

                <p:submenu id="m_registre" label="Registre &amp; Agrément" icon="pi pi-verified" rendered="#{menuBean.registreAgrementMenuVisible}">
                    <p:menuitem id="m_registre_info" value="Bientôt disponible" icon="pi pi-info-circle" disabled="true" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- AIDE SOCIALE                                            -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_mes_aides" label="Aide Sociale" icon="pi pi-heart" rendered="#{menuBean.mesAidesSocialesMenuVisible}">
                    <p:menuitem id="m_demande_aide" value="Faire une Demande" icon="pi pi-plus" outcome="#{paths.aideDemande}" />
                    <p:menuitem id="m_mes_demandes_aide" value="Mes Demandes" icon="pi pi-list" outcome="#{paths.aideRequests}" />
                    <p:menuitem id="m_historique_aides" value="Historique" icon="pi pi-clock" outcome="#{paths.aideHistorique}" />
                    <p:menuitem id="m_traitement_aide" value="Traitement des Demandes" icon="pi pi-cog" outcome="#{paths.aideTraitement}" rendered="#{menuBean.gestionAidesSocialesMenuVisible}" />
                    <p:menuitem id="m_suivi_aide" value="Suivi des Bénéficiaires" icon="pi pi-eye" outcome="#{paths.aideApproved}" rendered="#{menuBean.gestionAidesSocialesMenuVisible}" />
                    <p:menuitem id="m_statistiques_aides" value="Statistiques Sociales" icon="pi pi-chart-line" outcome="#{paths.aideStatistiques}" rendered="#{menuBean.gestionAidesSocialesMenuVisible}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- ÉVÉNEMENTS                                              -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_evenements" label="Événements" icon="pi pi-calendar" rendered="#{menuBean.mesEvenementsMenuVisible}">
                    <p:menuitem id="m_calendrier" value="Calendrier" icon="pi pi-calendar-plus" outcome="#{paths.evenementCalendrier}" />
                    <p:menuitem id="m_mes_inscriptions_events" value="Mes Inscriptions" icon="pi pi-list" outcome="#{paths.evenementParticipants}" />
                    <p:menuitem id="m_creation_evenement" value="Nouvel Événement" icon="pi pi-plus" outcome="#{paths.evenementCreation}" rendered="#{menuBean.gestionEvenementsMenuVisible}" />
                    <p:menuitem id="m_planification" value="Planification" icon="pi pi-clock" outcome="#{paths.evenementPlanification}" rendered="#{menuBean.gestionEvenementsMenuVisible}" />
                    <p:menuitem id="m_logistique" value="Logistique" icon="pi pi-truck" outcome="#{paths.evenementLogistique}" rendered="#{menuBean.gestionEvenementsMenuVisible}" />
                    <p:menuitem id="m_gestion_generale_evenements" value="Gestion Générale" icon="pi pi-cog" outcome="#{paths.evenementGestion}" rendered="#{menuBean.gestionEvenementsMenuVisible}" />
                    <p:menuitem id="m_bilan_evenements" value="Bilans" icon="pi pi-chart-bar" outcome="#{paths.evenementBilan}" rendered="#{menuBean.gestionEvenementsMenuVisible}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- COMMUNICATION                                           -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_communications" label="Communication" icon="pi pi-envelope" rendered="#{menuBean.mesCommunicationsMenuVisible}">
                    <p:menuitem id="m_messagerie" value="Messagerie" icon="pi pi-comments" outcome="#{paths.communicationConversations}" />
                    <p:menuitem id="m_mes_notifications" value="Mes Notifications" icon="pi pi-bell" outcome="#{paths.communicationNotifications}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- DOCUMENTS                                               -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_documents" label="Documents" icon="pi pi-folder" rendered="#{menuBean.documentsMenuVisible}">
                    <p:menuitem id="m_mes_documents" value="Mes Documents" icon="pi pi-file" outcome="#{paths.documentsMesDocuments}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- RAPPORTS ET ANALYSES                                    -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_rapports" label="Rapports" icon="pi pi-chart-bar" rendered="#{menuBean.rapportsMenuVisible}">
                    <p:menuitem id="m_tableaux_bord" value="Tableaux de Bord" icon="pi pi-chart-line" outcome="#{paths.rapportTableauxBord}" />
                    <p:menuitem id="m_rapport_membres" value="Rapport Membres" icon="pi pi-users" outcome="#{paths.rapportMembres}" />
                    <p:menuitem id="m_rapport_finances" value="Rapport Financier" icon="pi pi-dollar" outcome="#{paths.rapportFinances}" rendered="#{menuBean.rapportFinancierVisible}" />
                    <p:menuitem id="m_rapport_activites" value="Rapport d'Activités" icon="pi pi-chart-line" outcome="#{paths.rapportActivites}" />
                    <p:menuitem id="m_export" value="Exports" icon="pi pi-download" outcome="#{paths.rapportExport}" rendered="#{menuBean.exportsPersonnalisesVisible}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- MON ESPACE PERSONNEL                                    -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_personnel" label="Mon Espace" icon="pi pi-user">
                    <p:menuitem id="m_mon_profil" value="Mon Profil" icon="pi pi-user-edit" outcome="#{paths.personnelProfil}" />
                    <p:menuitem id="m_mes_preferences" value="Mes Préférences" icon="pi pi-cog" outcome="#{paths.personnelPreferences}" />
                    <p:menuitem id="m_personnel_notifications" value="Mes Notifications" icon="pi pi-bell" outcome="#{paths.personnelNotifications}" />
                    <p:menuitem id="m_parametres_compte" value="Paramètres Compte" icon="pi pi-lock" outcome="#{paths.personnelParametres}" />
                </p:submenu>

                <!-- ════════════════════════════════════════════════════════ -->
                <!-- AIDE ET SUPPORT                                         -->
                <!-- ════════════════════════════════════════════════════════ -->
                <p:submenu id="m_aide_documentation" label="Aide" icon="pi pi-question-circle">
                    <p:menuitem id="m_faq" value="Questions Fréquentes" icon="pi pi-question" outcome="#{paths.aideFaq}" />
                    <p:menuitem id="m_support" value="Contacter le Support" icon="pi pi-phone" outcome="#{paths.aideSupport}" />
                    <p:menuitem id="m_apropos" value="À Propos" icon="pi pi-info" outcome="#{paths.aideApropos}" />
                </p:submenu>

            </fr:menu>
        </h:form>
    </div>
</div>

</ui:composition>