{# ==== CONTEXTE EFFECTIF (roles vs entité active) ==== #}
{% set isMixed = app.user and app.user.userType == 'MIXED' %}
{% set active = app.session.get('active_entity') %}
{% set activeType = (active ? (active.type|upper)|replace({'-':'_',' ':'_'}) : null) %}
{# Quand MIXED + entité active => on force le contexte via l’entité #}
{% set ctxGarage = isMixed and active and activeType starts with 'GARAGE'
? true : (not isMixed and is_granted('CTX_GARAGE')) %}
{% set ctxDistrib = isMixed and active and (activeType starts with 'DISTR')
? true : (not isMixed and is_granted('CTX_DISTRIBUTOR')) %}
{% set ctxGroup = isMixed and active and (
activeType starts with 'GROUPE_DISTRIBUTEUR'
or activeType starts with 'GROUPE'
or activeType starts with 'GROUP')
? true : (not isMixed and (is_granted('CTX_GROUP') or is_granted('ROLE_ALL_DISTIBUTEUR'))) %}
{% set ctxDpan = not isMixed and is_granted('CTX_DPAN') %}
<!-- NAVIGATION VERTICALE -->
<nav class="side-navbar z-index-40">
{# ============ BONUS : MIXED sans entité active ============ #}
{% if isMixed and not active %}
<div class="dropdown-divider" style="margin-top:18px;"></div>
<div class="px-3 py-4 text-center text-muted small">
<i class="fa-solid fa-shuffle me-2"></i>
Sélectionnez une entité pour accéder au menu.
</div>
{# On arrête ici l’affichage du menu #}
{% else %}
{# =================== EN-TÊTE =================== #}
{% if ctxGarage %}
<div class="sidebar-header d-flex align-items-center py-4 px-3">
<a class="d-inline-block" href="{{ path('dashboard.customer') }}">
<img class="avatar shadow-0 img-fluid rounded-circle"
src="/images/identite/noun-garage-2580385-00407D.png" alt="">
</a>
<div class="ms-3 title">
<h1 class="h4 mb-2">
<span class="text-blue-nf">
{{ isMixed ? active.label|upper : app.user.customerUser.raisonSociale|upper }}
</span>
</h1>
<p class="text-sm text-gray-500 fw-light mb-0 lh-1">{{ app.user.fullName }}</p>
</div>
</div>
{% endif %}
{% if ctxDpan %}
<div class="sidebar-header d-flex align-items-center py-4 px-3">
<a class="d-inline-block" href="{{ path('demande_prestation.suivi') }}">
<img class="avatar shadow-0 img-fluid rounded-circle"
src="/images/identite/cropped-FavIconDPANGoodDimension.png" alt="">
</a>
<div class="ms-3 title">
<h1 class="h4 mb-2"><span class="text-green-dpan">DPAN</span></h1>
<p class="text-sm text-gray-500 fw-light mb-0 lh-1">{{ app.user.fullName }}</p>
</div>
</div>
{% endif %}
{% if ctxDistrib %}
<div class="sidebar-header d-flex align-items-center py-4 px-3">
<a class="d-inline-block" href="{{ path('dashboard.distributor') }}">
{% set image_path = not isMixed ? app.user.distributeur.getGroupReseau.imageGroupe : null %}
{% if image_path %}
<img class="avatar shadow-0 img-fluid rounded-circle"
src="{{ asset('images/identite/groupDistributeur/' ~ image_path) }}" alt="">
{% else %}
<img class="avatar shadow-0 img-fluid rounded-circle"
src="/images/identite/placeholder-distrib.png" alt="">
{% endif %}
</a>
<div class="ms-3 title">
<h1 class="h4 mb-2">
<span class="text-blue-nf">
{{ isMixed ? active.label|upper : app.user.distributeur.nomMagasin|upper }}
</span>
</h1>
<p class="text-sm text-gray-500 fw-light mb-0 lh-1">{{ app.user.fullName }}</p>
</div>
</div>
{% endif %}
{% if ctxGroup %}
<div class="sidebar-header d-flex align-items-center py-4 px-3">
<a class="d-inline-block" href="{{ path('complete_vue') }}">
{% set image_path = not isMixed ? app.user.groupDistributeurId.imageGroupe : null %}
{% if image_path %}
<img class="avatar shadow-0 img-fluid rounded-circle"
src="{{ asset('images/identite/groupDistributeur/' ~ image_path) }}" alt="">
{% else %}
<img class="avatar shadow-0 img-fluid rounded-circle"
src="/images/identite/placeholder-group.png" alt="">
{% endif %}
</a>
<div class="ms-3 title">
<h1 class="h4 mb-2">
<span class="text-blue-nf">
{{ isMixed ? active.label|upper : app.user.groupDistributeurId|upper }}
</span>
</h1>
<p class="text-sm text-gray-500 fw-light mb-0 lh-1">{{ app.user.fullName }}</p>
</div>
</div>
{% endif %}
{# ================ FIN EN-TÊTE ================== #}
<!-- MENU -->
<div class="dropdown-divider" style="margin-top:18px;"></div>
<span class="text-uppercase text-gray-400 text-xs letter-spacing-0 mx-3 px-2 heading">Principal</span>
<ul class="list-unstyled py-4">
{# DASHBOARDS #}
{% if ctxGarage %}
<li class="sidebar-item {{ app.request.get('_route') == 'dashboard.customer' ? 'active' }}">
<a class="sidebar-link" href="{{ path('dashboard.customer') }}">
<i class="fas fa-house me-xl-2"></i>Tableau de bord
</a>
</li>
{% endif %}
{% if ctxDistrib %}
<li class="sidebar-item {{ app.request.get('_route') == 'dashboard.distributor' ? 'active' }}">
<a class="sidebar-link" href="{{ path('dashboard.distributor') }}">
<i class="fas fa-store me-xl-2"></i>Tableau de bord
</a>
</li>
{% endif %}
{# DEMANDE PRESTATION (garage + distrib + dpan) #}
{% if ctxGarage or ctxDistrib or ctxDpan %}
{% set dpRoutes = [
'demande_prestation.suivi','demande_prestation.index',
'demande_prestation.suivi.customer','demande_prestation.suivi.customer.unique',
'demande_prestation.suivi.user','demande_prestation.suivi.user.unique',
'demande_prestation.suivi.distributor','demande_prestation.suivi.distributor.unique'
] %}
<li class="sidebar-item {{ app.request.get('_route') in dpRoutes ? 'active' }}">
<a class="sidebar-link" href="#formsDropdown" data-bs-toggle="collapse"
aria-expanded="{{ app.request.get('_route') in dpRoutes ? 'true' : 'false' }}">
<i class="fas fa-tasks me-xl-2"></i>Demande prestation
</a>
<ul class="{{ app.request.get('_route') in dpRoutes ? 'list-unstyled collapse show' : 'collapse list-unstyled' }}" id="formsDropdown">
{% if ctxDistrib or ctxDpan %}
<li class="{{ app.request.get('_route') in [
'demande_prestation.suivi','demande_prestation.suivi.customer',
'demande_prestation.suivi.user','demande_prestation.suivi.distributor'
] ? 'active' }}">
<a class="sidebar-link" href="{{ path('demande_prestation.suivi') }}">
<i class="fas fa-eye me-xl-2"></i>Suivi des demandes
</a>
</li>
{% endif %}
{% if ctxGarage %}
<li class="{{ app.request.get('_route') == 'demande_prestation.index' ? 'active' }}">
<a class="sidebar-link" href="{{ path('demande_prestation.index') }}">
<i class="fas fa-plus-circle me-xl-2"></i>Nouvelle demande
</a>
</li>
{% endif %}
</ul>
</li>
{% endif %}
{# GESTION DES UTILISATEURS (distributeur) #}
{% if ctxDistrib %}
<li class="sidebar-item">
<a class="sidebar-link" href="#userDropdown" data-bs-toggle="collapse"
aria-expanded="{{ app.request.get('_route') == 'security.registrationByDistributeur' ? 'true' : 'false' }}">
<i class="fas fa-users me-xl-2"></i>Gestion des utilisateurs
</a>
<ul class="{{ app.request.get('_route') == 'security.registrationByDistributeur' ? 'list-unstyled collapse show' : 'collapse list-unstyled' }}" id="userDropdown">
<li class="{{ app.request.get('_route') == 'security.registrationByDistributeur' ? 'active' }}">
<a class="sidebar-link" href="{{ path('security.registrationByDistributeur') }}">
<i class="fas fa-user-plus me-xl-2"></i>Enregistrer un client
</a>
</li>
</ul>
</li>
{% endif %}
{# VUE COMPLÈTE (distrib / group / dpan) #}
{% if ctxDistrib or ctxGroup or ctxDpan %}
<li class="sidebar-item {{ app.request.get('_route') == 'complete_vue' ? 'active' }}">
<a class="sidebar-link" href="{{ path('complete_vue') }}">
<i class="fas fa-table me-xl-2"></i>Vue complète
</a>
</li>
{% endif %}
{# ADMIN (reste basé sur les rôles) #}
{% if is_granted('ROLE_ADMIN') %}
<li class="sidebar-item">
<a class="sidebar-link" href="{{ path('admin') }}">
<i class="fas fa-cogs me-xl-2"></i>Administration
</a>
</li>
{# --- Import / Export --- #}
<li class="sidebar-item {{ app.request.get('_route') in ['export.excel.page','customer_upload','import_valid_customers'] ? 'active' }}">
<a class="sidebar-link" href="#componentsDropdown" data-bs-toggle="collapse"
aria-expanded="{{ app.request.get('_route') in ['customer_upload','export.excel.page'] ? 'true' : 'false' }}">
<i class="fas fa-file-export me-xl-2"></i>Import / Export
</a>
<ul class="{{ app.request.get('_route') in ['export.excel.page','customer_upload','import_valid_customers'] ? 'list-unstyled collapse show' : 'collapse list-unstyled' }}" id="componentsDropdown">
<li class="{{ app.request.get('_route') in ['customer_upload','import_valid_customers'] ? 'active' }}">
<a class="sidebar-link" href="{{ path('customer_upload') }}">
<i class="fas fa-upload me-xl-2"></i>Import Garage
</a>
</li>
<li class="{{ app.request.get('_route') == 'export.excel.page' ? 'active' }}">
<a class="sidebar-link" href="{{ path('export.excel.page') }}">
<i class="fas fa-file-excel me-xl-2"></i>Export
</a>
</li>
</ul>
</li>
{# --- Statistiques --- #}
{% set statsActive = app.request.get('_route') == 'demandes_par_annee' %}
<li class="sidebar-item {{ statsActive ? 'active' }}">
<a class="sidebar-link" href="#statsDropdown" data-bs-toggle="collapse"
aria-expanded="{{ statsActive ? 'true' : 'false' }}">
<i class="fas fa-chart-line me-xl-2"></i>Statistiques
</a>
<ul class="{{ statsActive ? 'list-unstyled collapse show' : 'collapse list-unstyled' }}" id="statsDropdown">
<li class="{{ statsActive ? 'active' }}">
<a class="sidebar-link" href="{{ path('demandes_par_annee') }}">
<i class="fas fa-calendar-alt me-xl-2"></i>Demandes années
</a>
</li>
</ul>
</li>
{% endif %}
</ul>
{% endif %} {# fin du bonus "blocage si pas d’entité" #}
</nav>