<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <script src="https://unpkg.com/htmx.org@1.9.11"></script>
    <meta charset="UTF-8">
    <title>Paramétrage - Catégories</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style> body { font-family: 'Inter', sans-serif; } </style>
</head>
<body class="bg-gray-50 text-gray-900 flex h-screen overflow-hidden">
    <!-- Sidebar -->
    <div th:replace="~{fragments/sidebar :: sidebar}"></div>

    <main class="flex-1 flex flex-col h-screen overflow-hidden">
        <header class="h-16 bg-white border-b border-gray-200 flex items-center px-6">
            <h2 class="text-lg font-semibold text-gray-800">Catégories Sportives</h2>
        </header>

        <div class="flex-1 overflow-auto p-6">
            <div class="flex justify-between items-center mb-6">
                <h3 class="text-xl font-bold text-gray-900">Liste des Catégories</h3>
                <a th:href="@{/categories/new}" class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-blue-700">
                    + Nouvelle Catégorie
                </a>
            </div>

            <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="w-full text-left border-collapse min-w-[800px]">
                    <thead>
                        <tr class="bg-gray-50 text-gray-500 text-sm uppercase tracking-wider border-b border-gray-200">
                            <th class="py-3 px-6 font-medium text-left">Nom de la catégorie</th>
                            <th class="py-3 px-6 font-medium text-center">Année Min</th>
                            <th class="py-3 px-6 font-medium text-center">Année Max</th>
                            <th class="py-3 px-6 font-medium text-right">Tarif (Talangeois)</th>
                            <th class="py-3 px-6 font-medium text-right">Tarif (Hors Commune)</th>
                            <th class="py-3 px-6 font-medium text-right">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200 text-sm">
                        <tr th:if="${#lists.isEmpty(categories)}">
                            <td colspan="6" class="py-8 text-center text-gray-500">Aucune catégorie n'est paramétrée.</td>
                        </tr>
                        <tr th:each="cat : ${categories}" class="hover:bg-gray-50 transition-colors">
                            <td class="py-4 px-6 font-medium text-gray-900" th:text="${cat.nom}">U15</td>
                            <td class="py-4 px-6 text-center text-gray-600" th:text="${cat.anneeMin}">2010</td>
                            <td class="py-4 px-6 text-center text-gray-600" th:text="${cat.anneeMax}">2011</td>
                            <td class="py-4 px-6 text-right font-medium text-blue-600" th:text="${cat.tarifBase + ' €'}">100.00 €</td>
                            <td class="py-4 px-6 text-right font-medium text-purple-600" th:text="${cat.tarifExterieur != null ? cat.tarifExterieur + ' €' : '-'}">130.00 €</td>
                            <td class="py-4 px-6 text-right flex justify-end space-x-3 items-center">
                                <a th:href="@{/categories/{id}/edit(id=${cat.id})}" class="text-indigo-600 hover:text-indigo-900 font-medium bg-indigo-50 px-3 py-1 rounded-lg">Modifier</a>
                                <form th:action="@{/categories/{id}/delete(id=${cat.id})}" method="post" onsubmit="return confirm('Supprimer cette catégorie ?');">
                                    <button type="submit" class="text-red-600 hover:text-red-800 font-medium">Supprimer</button>
                                </form>
                            </td>
                        </tr>
                    </tbody>
                    </table>
                </div>
            </div>
        </div>
    </main>
</body>
</html>
