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

{% block title %}Types 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">Types de frais</h1><p>Catégories facturables propres à {{ ecole.nom }}.</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_type_new') }}">Nouveau type</a>
            </div>
        </section>
        <section class="admin-card">
            <table class="finance-table">
                <thead><tr><th>Code</th><th>Libellé</th><th>Nature</th><th>Périodicité</th><th>Montant</th><th>Statut</th><th></th></tr></thead>
                <tbody>
                {% for type in types %}
                    <tr>
                        <td><strong>{{ type.code }}</strong></td>
                        <td>{{ type.libelle }}</td>
                        <td>{{ type.nature|replace({'_':' '})|title }}</td>
                        <td>{{ type.periodicite ? type.periodicite|replace({'_':' '})|title : '-' }}</td>
                        <td>{{ type.montantDefaut ? type.montantDefaut|number_format(0, ',', ' ') ~ ' FCFA' : '-' }}</td>
                        <td>{% include 'components/admin/status_badge.html.twig' with {label: type.actif ? 'Actif' : 'Inactif', tone: type.actif ? 'success' : 'neutral'} only %}</td>
                        <td>
                            <div class="finance-actions">
                                <a class="admin-text-link" href="{{ path('school_finance_type_edit', {id: type.id}) }}">Modifier</a>
                                <form method="post" action="{{ path('school_finance_type_delete', {id: type.id}) }}" onsubmit="return confirm('Supprimer ou désactiver ce type de frais ?');">
                                    <input type="hidden" name="_token" value="{{ csrf_token('delete_type_frais_' ~ type.id) }}">
                                    <button class="admin-text-link admin-action-danger" type="submit">Supprimer</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                {% else %}
                    <tr><td colspan="7">Aucun type de frais configuré.</td></tr>
                {% endfor %}
                </tbody>
            </table>
        </section>
    </div>
{% endblock %}
