<!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 - Saisons</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 fragment -->
    <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">Saisons du Club</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 Saisons</h3>
                <a th:href="@{/saisons/new}" class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-medium hover:bg-blue-700">
                    + Nouvelle Saison
                </a>
            </div>

            <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
                <table class="w-full text-left border-collapse">
                    <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 Saison</th>
                            <th class="py-3 px-6 font-medium text-center">Statut</th>
                            <th class="py-3 px-6 font-medium text-center">Inscriptions Publiques</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(saisons)}">
                            <td colspan="4" class="py-8 text-center text-gray-500">Aucune saison configurée.</td>
                        </tr>
                        <tr th:each="saison : ${saisons}" class="hover:bg-gray-50 transition-colors">
                            <td class="py-4 px-6 font-medium text-gray-900" th:text="${saison.nom}">Saison 2024-2025</td>
                            <td class="py-4 px-6 text-center">
                                <span th:if="${saison.estActive}" class="px-3 py-1 rounded-full text-xs font-medium bg-green-100 text-green-800">
                                    Saison Active
                                </span>
                                <span th:unless="${saison.estActive}" class="px-3 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-600">
                                    Clôturée
                                </span>
                            </td>
                            <td class="py-4 px-6 text-center">
                                <form th:if="${saison.estActive}" th:action="@{/saisons/{id}/toggle-inscriptions(id=${saison.id})}" method="post">
                                    <button type="submit" th:class="${saison.inscriptionsOuvertes ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'} + ' px-3 py-1 rounded-full text-xs font-medium hover:opacity-80 transition-opacity'" title="Cliquez pour ouvrir/fermer">
                                        <span th:text="${saison.inscriptionsOuvertes ? 'Ouvertes' : 'Fermées'}"></span>
                                    </button>
                                </form>
                                <span th:unless="${saison.estActive}" class="text-gray-400 text-xs">-</span>
                            </td>
                            <td class="py-4 px-6 text-right flex justify-end space-x-3 items-center">
                                <form th:if="${!saison.estActive}" th:action="@{/saisons/{id}/activer(id=${saison.id})}" method="post">
                                    <button type="submit" class="text-indigo-600 hover:text-indigo-900 font-medium bg-indigo-50 px-3 py-1 rounded-lg">Définir Active</button>
                                </form>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </main>
</body>
</html>
