<!DOCTYPE html>
<html lang="ru" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorate="~{default}">

<head>
    <title>Панель администратора (пользователи)</title>
</head>

<body th:with="bodyClass='bg-white', mainClass='my-0'">
    <main layout:fragment="content">
        <th:block th:switch="${items.size()}">
            <h2 class="mt-4 text-center" th:case="0">Данные отсутствуют</h2>
            <th:block th:case="*">
                <div class="row gy-3">
                    <div class="col-12 mt-4 px-0">
                        <div class="block d-flex justify-content-center fs-2 fw-bold mb-3 mb-sm-4" id="admin-title">
                            Пользователи
                        </div>
                    </div>
                    <div class="col-12 px-0">
                        <div class="block table-responsive">
                            <table class="table table-hover table-bordered align-middle">
                                <caption></caption>
                                <thead>
                                    <tr>
                                        <th scope="col">ID</th>
                                        <th scope="col">Логин</th>
                                        <th scope="col">Email</th>
                                        <th scope="col">Имя</th>
                                        <th scope="col">Фамилия</th>
                                        <th scope="col">Роль</th>
                                        <th scope="col"></th>
                                        <th scope="col"></th>
                                    </tr>
                                </thead>
                                <tbody class="table-group-divider">
                                    <tr th:each="user : ${items}">
                                        <th scope="row" th:text="${user.id}"></th>
                                        <td th:text="${user.login}"></td>
                                        <td th:text="${user.email}"></td>
                                        <td th:text="${user.firstname}"></td>
                                        <td th:text="${user.lastname}"></td>
                                        <td th:text="${user.role}"></td>
                                        <td>
                                            <form th:action="@{/admin/user/edit/{id}(id=${user.id})}" method="get">
                                                <input type="hidden" th:name="page" th:value="${page}">
                                                <button type="submit" class="btn btn-primary w-100">Редактировать</button>
                                            </form>
                                        </td>
                                        <td>
                                            <form th:action="@{/admin/user/delete/{id}(id=${user.id})}" method="post">
                                                <input type="hidden" th:name="page" th:value="${page}">
                                                <button type="submit" class="btn btn-primary w-100"
                                                    onclick="return confirm('Вы уверены?')">Удалить</button>
                                            </form>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <th:block th:replace="~{ pagination :: pagination (
                                                                        url=${'admin/user'},
                                                                        totalPages=${totalPages},
                                                                        currentPage=${currentPage},
                                                                        filter='',
                                                                        searchInfo='') }" />
                </div>
            </th:block>
    </main>
</body>

</html>