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

{% block title %}Règles de frais | SALSABIL Madrassas{% endblock %}

{% block content %}
    <style>
        .finance-table{width:100%;border-collapse:separate;border-spacing:0 .55rem}
        .finance-table th{font-size:.72rem;text-transform:uppercase;color:#64748b;text-align:left;padding:.35rem .75rem}
        .finance-table td{background:#fff;padding:.8rem .75rem;border-top:1px solid rgba(15,92,69,.1);border-bottom:1px solid rgba(15,92,69,.1);vertical-align:middle}
        .finance-table td:first-child{border-left:1px solid rgba(15,92,69,.1);border-radius:12px 0 0 12px}
        .finance-table td:last-child{border-right:1px solid rgba(15,92,69,.1);border-radius:0 12px 12px 0;text-align:right}
        .finance-actions{display:flex;gap:.5rem;justify-content:flex-end;flex-wrap:wrap}
    </style>
    <div class="admin-page-stack">
        <section class="admin-page-header">
            <div><p class="admin-eyebrow">FINANCES</p><h1 class="admin-page-title">Règles de frais</h1><p>Tarifs appliqués par année, section ou classe.</p></div>
            <div class="finance-actions">
                <a class="admin-btn admin-btn-light" href="{{ path('school_finance_index') }}">Retour finance</a>
                <a class="admin-btn admin-btn-primary" href="{{ path('school_finance_regle_new') }}">Nouvelle règle</a>
            </div>
        </section>
        <section class="admin-card">
            <table class="finance-table">
                <thead><tr><th>Type</th><th>Portée</th><th>Périodicité</th><th>Montant</th><th>Statut</th><th></th></tr></thead>
                <tbody>
                {% for regle in regles %}
                    <tr>
                        <td><strong>{{ regle.typeFrais ? regle.typeFrais.libelle : '-' }}</strong></td>
                        <td>
                            {{ regle.anneeScolaire ? regle.anneeScolaire.libelle : 'Toutes années' }}
                            · {{ regle.classe ? regle.classe.nom : (regle.section ? regle.section.nom : 'Toute l’école') }}
                        </td>
                        <td>{{ regle.periodicite ? regle.periodicite|replace({'_':' '})|title : (regle.typeFrais and regle.typeFrais.periodicite ? regle.typeFrais.periodicite|replace({'_':' '})|title : '-') }}</td>
                        <td>{{ regle.montant|number_format(0, ',', ' ') }} FCFA</td>
                        <td>{% include 'components/admin/status_badge.html.twig' with {label: regle.actif ? 'Actif' : 'Inactif', tone: regle.actif ? 'success' : 'neutral'} only %}</td>
                        <td>
                            <div class="finance-actions">
                                <a class="admin-text-link" href="{{ path('school_finance_regle_edit', {id: regle.id}) }}">Modifier</a>
                                <form method="post" action="{{ path('school_finance_regle_delete', {id: regle.id}) }}" onsubmit="return confirm('Supprimer ou désactiver cette règle ?');">
                                    <input type="hidden" name="_token" value="{{ csrf_token('delete_regle_frais_' ~ regle.id) }}">
                                    <button class="admin-text-link admin-action-danger" type="submit">Supprimer</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                {% else %}
                    <tr><td colspan="6">Aucune règle de frais configurée.</td></tr>
                {% endfor %}
                </tbody>
            </table>
        </section>
    </div>
{% endblock %}
