{% extends '_admin/base.html.twig' %}

{% set current_route = app.request.attributes.get('_route')|default('') %}
{% set current_school = ecole|default(app.user and app.user.ecole ? app.user.ecole : null) %}
{% set current_year = currentAnnee|default(null) %}

{% block admin_space %}school{% endblock %}
{% block title %}École | SALSABIL Madrassas{% endblock %}
{% block brand_title %}{{ current_school ? current_school.nom : 'SALSABIL' }}{% endblock %}
{% block brand_subtitle %}Gestion de madrassa{% endblock %}
{% block brand_logo %}
    {% if current_school and current_school.logo %}
        <img class="admin-brand-logo admin-brand-logo-school" src="{{ asset(current_school.logo) }}" alt="{{ current_school.nom }}">
    {% else %}
        {{ parent() }}
    {% endif %}
{% endblock %}
{% block mobile_brand_title %}{{ current_school ? current_school.nom : 'SALSABIL' }}{% endblock %}
{% block mobile_brand_subtitle %}Gestion de madrassa{% endblock %}
{% block mobile_brand_logo %}
    {% if current_school and current_school.logo %}
        <img class="admin-mobile-brand-logo admin-brand-logo-school" src="{{ asset(current_school.logo) }}" alt="{{ current_school.nom }}">
    {% else %}
        {{ parent() }}
    {% endif %}
{% endblock %}
{% block brand_link %}{{ path('school_dashboard') }}{% endblock %}
{% block user_meta %}Admin école{% endblock %}
{% block search_placeholder %}Rechercher un étudiant, une classe...{% endblock %}

{% block brand_color %}{{ current_school and current_school.couleurPrincipale ? current_school.couleurPrincipale : '#0f3433' }}{% endblock %}
{% block accent_color %}{{ current_school and current_school.couleurAccent ? current_school.couleurAccent : '#c5a059' }}{% endblock %}

{% block sidebar_context %}
    <div class="admin-campus-pill">
        <div class="admin-campus-label">Madrassa courante</div>
        <div class="admin-campus-name">{{ current_school ? current_school.nom : 'Non définie' }}</div>
        {% if current_year %}
            <div class="admin-campus-label">Année en cours : {{ current_year.libelle }}</div>
        {% endif %}
        {% if current_school and current_school.slug %}
            <a class="admin-campus-link" href="{{ public_school_url(current_school) }}" target="_blank" rel="noopener">Voir la page publique</a>
        {% endif %}
    </div>
{% endblock %}

{% block mobile_sidebar_context %}{{ block('sidebar_context') }}{% endblock %}

{% block sidebar_items %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_dashboard'), icon: 'dashboard', label: 'Tableau de bord', active: current_route == 'school_dashboard'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_etudiant_index'), icon: 'school', label: 'Étudiants', active: current_route starts with 'school_etudiant_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_inscription_index'), icon: 'fact_check', label: 'Inscriptions', active: current_route starts with 'school_inscription_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_classe_index'), icon: 'meeting_room', label: 'Classes', active: current_route starts with 'school_classe_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_niveau_index'), icon: 'menu_book', label: 'Niveaux', active: current_route starts with 'school_niveau_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_section_index'), icon: 'category', label: 'Sections', active: current_route starts with 'school_section_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_finance_index'), icon: 'account_balance', label: 'Finances', active: current_route starts with 'school_finance_' or current_route starts with 'school_etudiant_finance'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_paiement_index'), icon: 'payments', label: 'Paiements', active: current_route starts with 'school_paiement_' or current_route starts with 'school_etudiant_paiement_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_depense_index'), icon: 'receipt_long', label: 'Dépenses', active: current_route starts with 'school_depense_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_annee_index'), icon: 'event_available', label: 'Années scolaires', active: current_route starts with 'school_annee_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: path('school_configuration_edit'), icon: 'tune', label: 'Configuration', active: current_route starts with 'school_configuration_'} %}
    {% include 'components/admin/sidebar_link.html.twig' with {href: '#', icon: 'manage_accounts', label: 'Utilisateurs'} %}
{% endblock %}

{% block sidebar_cta %}
    <a class="admin-primary-cta" href="{{ current_school ? public_registration_url(current_school) : '#' }}" target="_blank" rel="noopener">
        <span class="material-symbols-outlined">add</span>
        <span>Nouvelle inscription</span>
    </a>
{% endblock %}

{% block sidebar_footer_links %}
    <a class="admin-nav-link admin-nav-link-danger" href="{{ path('app_logout') }}">
        <span class="material-symbols-outlined">logout</span>
        <span>Déconnexion</span>
    </a>
{% endblock %}
