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

{% block title %}Catégories dépenses | SALSABIL Madrassas{% endblock %}

{% block content %}
    <style>
        .category-actions{display:flex;gap:.75rem;flex-wrap:wrap}
        .category-table{width:100%;border-collapse:separate;border-spacing:0 .55rem}
        .category-table th{font-size:.72rem;text-transform:uppercase;color:#64748b;text-align:left;padding:.35rem .75rem}
        .category-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}
        .category-table td:first-child{border-left:1px solid rgba(15,92,69,.1);border-radius:12px 0 0 12px}
        .category-table td:last-child{border-right:1px solid rgba(15,92,69,.1);border-radius:0 12px 12px 0;text-align:right}
    </style>
    <div class="admin-page-stack">
        <section class="admin-page-header">
            <div>
                <p class="admin-eyebrow">DÉPENSES</p>
                <h1 class="admin-page-title">Catégories de dépenses</h1>
                <p>Organisation des sorties de caisse de {{ ecole.nom }}.</p>
            </div>
            <div class="category-actions">
                <a class="admin-btn admin-btn-light" href="{{ path('school_depense_index') }}">Voir dépenses</a>
                <a class="admin-btn admin-btn-primary" href="{{ path('school_depense_category_new') }}">Nouvelle catégorie</a>
            </div>
        </section>

        <section class="admin-card">
            <table class="category-table">
                <thead><tr><th>Code</th><th>Libellé</th><th>Description</th><th>Ordre</th><th>Statut</th><th></th></tr></thead>
                <tbody>
                {% for categorie in categories %}
                    <tr>
                        <td><strong>{{ categorie.code }}</strong></td>
                        <td>{{ categorie.libelle }}</td>
                        <td>{{ categorie.description ?: '-' }}</td>
                        <td>{{ categorie.ordre }}</td>
                        <td>{% include 'components/admin/status_badge.html.twig' with {label: categorie.actif ? 'Active' : 'Inactive', tone: categorie.actif ? 'success' : 'neutral'} only %}</td>
                        <td>
                            <div class="category-actions" style="justify-content:flex-end">
                                <a class="admin-text-link" href="{{ path('school_depense_category_edit', {id: categorie.id}) }}">Modifier</a>
                                <form method="post" action="{{ path('school_depense_category_delete', {id: categorie.id}) }}" onsubmit="return confirm('Supprimer ou désactiver cette catégorie ?');">
                                    <input type="hidden" name="_token" value="{{ csrf_token('delete_categorie_depense_' ~ categorie.id) }}">
                                    <button class="admin-text-link" type="submit" style="border:0;background:transparent;color:#9f1239">Supprimer</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                {% else %}
                    <tr><td colspan="6">Aucune catégorie de dépense.</td></tr>
                {% endfor %}
                </tbody>
            </table>
        </section>
    </div>
{% endblock %}
