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

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Пользователи</title>
</head>

<body>
    <main class="text-center" layout:fragment="content">
        <th:block th:switch="${items.size()}">
            <h2 th:case="0">Данные отсутствуют</h2>
            <th:block th:case="*">
                <span class="mainSt">
                    <b>Пользователи</b>
                </span>
                <div>
                    <a href="/users/edit/" class="btn btn-danger">Добавить пользователя</a>
                </div>
                <table class="table">
                    <caption></caption>
                    <thead>
                        <tr>
                            <th scope="col" class="w-5">ID</th>
                            <th scope="col" class="w-10">Логин</th>
                            <th scope="col" class="w-25">Роль</th>
                            <th scope="col" class="w-50">Кафедра</th>
                            <th scope="col" class="w-10"></th>
                            <th scope="col" class="w-10"></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="user : ${items}">
                            <th scope="row" th:text="${user.id}"></th>
                            <td th:text="${user.login}"></td>
                            <td th:text="${user.role}"></td>
                            <td th:text="${user.departmentName}"></td>
                            <td>
                                <form th:action="@{/users/edit/{id}(id=${user.id})}" method="get">
                                    <button type="submit" class="btn btn-link button-link">
                                        <i class="fa fa-edit">Изменить</i>
                                    </button>
                                </form>
                            </td>
                            <td>
                                <form th:action="@{/users/delete/{id}(id=${user.id})}" method="post">
                                    <button type="submit" class="btn btn-link button-link"
                                        onclick="return confirm('Вы уверены?')">
                                        <i class="fa fa-trash">Удалить</i>
                                    </button>
                                </form>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </th:block>
            <th:block th:replace="~{ pagination :: pagination (
                                        url=${'users'},
                                        totalPages=${totalPages},
                                        currentPage=${currentPage}) }" />
        </th:block>
    </main>
</body>

</html>