<!DOCTYPE html>
<html th:replace="~{modele-page :: layout('__${#messages.msg('admin.panel.title')}__',~{::link} , ~{::#container-main})}" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
</head>
<body>
<div id="container-main" class="container mt-4">
    <h2 th:text="#{admin.categories.title}" class="mb-4">Liste des catégories modifiées</h2>
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead class="thead-dark">
            <tr>
                <th th:text="#{admin.categories.table.name}">Nom</th>
                <th th:text="#{admin.categories.table.action}">Action</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="categorie : ${categories}">
                <td>
                    <form th:action="@{/admin/update}" method="post">
                        <input type="text" name="newCategorie" id="newCategorie" th:value="${categorie.libelle}" class="form-control">
                        <input type="hidden" name="IdCategorie" id="IdCategorie" th:value="${categorie.id}">
                        <button type="submit" th:text="#{admin.categories.table.save}" class="btn btn-primary mt-2"></button>
                    </form>
                </td>
                <td>
                    <form th:action="@{/admin/deleteC}" method="post">
                        <input type="hidden" name="deleteIdCategorie" id="deleteIdCategorie" th:value="${categorie.id}">
                        <button type="submit" th:text="#{admin.categories.table.delete}" class="btn btn-danger mt-2"></button>
                    </form>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
    <form th:action="@{/admin/new}" th:object="${categorie}" method="post" class="mb-4">
        <input type="text" th:field="*{libelle}" id="nom" class="form-control">
        <button type="submit" th:text="#{admin.categories.table.add}" class="btn btn-success mt-2"></button>
    </form>

    <h2 th:text="#{admin.users.title}" class="mb-4">Liste des utilisateurs</h2>
    <div class="table-responsive">
        <table class="table table-bordered">
            <thead class="thead-dark">
            <tr>
                <th th:text="#{admin.users.table.id}">ID</th>
                <th th:text="#{admin.users.table.username}">Pseudo</th>
                <th th:text="#{admin.users.table.lastname}">Nom</th>
                <th th:text="#{admin.users.table.firstname}">Prénom</th>
                <th th:text="#{admin.users.table.email}">Email</th>
                <th th:text="#{admin.categories.table.action}">Action</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="user : ${userProfil}">
                <td th:text="${user.id}"></td>
                <td th:text="${user.pseudo}"></td>
                <td th:text="${user.nom}"></td>
                <td th:text="${user.prenom}"></td>
                <td th:text="${user.email}"></td>
                <td>
                    <form th:action="@{/admin/update/credit}" method="post">
                        <input type="number" name="newCredit" id="newCredit" th:value="${user.credit}" class="form-control">
                        <input type="hidden" name="idUser" id="idUser" th:value="${user.id}">
                        <button type="submit" class="btn btn-primary mt-2">Sauvegarder</button>
                    </form>
                </td>
                <td>
                    <form th:action="@{/admin/disabled}" method="post">
                        <input type="hidden" name="userDisabled" id="userDisabled" th:value="${user.id}">
                        <input type="hidden" name="isDis" id="isDis" th:value="${user.isDisabled}">
                        <button type="submit" th:text="${user.isDisabled}  ? 'Activer' : 'Désactiver'" class="btn btn-secondary mt-2"></button>
                    </form>
                    <form th:action="@{/admin/delete}" method="post">
                        <input type="hidden" name="userDelete" id="userDelete" th:value="${user.id}">
                        <button type="submit" class="btn btn-danger mt-2">Supprimer</button>
                    </form>
                    <form th:action="@{/admin/administrateur}" method="post">
                        <input type="hidden" name="userAdmin" id="userAdmin" th:value="${user.id}">
                        <input type="hidden" name="isAdmin" id="isAdmin" th:value="${user.admin}">
                        <button type="submit" th:text="${user.admin}  ? 'Retirer admin' : 'Ajouter admin'" class="btn btn-info mt-2"></button>
                    </form>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>
