<!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">
        <label class="mainSt d-flex justify-content-center" for="direction">
            <b>Направления</b>
        </label>
        <div class="d-flex justify-content-center">
            <form class="w-25" method="get">
                <button class = "btn button-link" name="reset" value="true" type="submit">
                    <i class = "fa fa-refresh">Сброс</i>
                </button>
                <div class="input-group mt-1">
                    <input class="form-control" type="text" name="name" th:value="${name}"
                        placeholder="Поиск направлений..." />
                    <button class="btn btn-primary" type="submit">
                        <i class="fa fa-search">Поиск</i>
                    </button>
                </div>
            </form>
        </div>
        <th:block th:switch="${items.size()}">
            <h2 th:case="0">Данные отсутствуют</h2>
            <th:block th:case="*">
                <div>
                    <a th:href="@{/directions/edit/(page=${page})}" class="btn btn-danger mt-4">Добавить направление</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-25">Кафедра</th>
                            <th scope="col" class="w-25">Предметы ЕГЭ</th>
                            <th scope="col" class="w-5"></th>
                            <th scope="col" class="w-5"></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="direction : ${items}">
                            <th scope="row" th:text="${direction.id}"></th>
                            <td th:text="${direction.code}"></td>
                            <td th:text="${direction.name}"></td>
                            <td th:text="${direction.departmentName}"></td>
                            <td th:text="${direction.things}"></td>
                            <td>
                                <form th:action="@{/directions/edit/{id}(id=${direction.id})}" method="get">
                                    <input type="hidden" th:name="page" th:value="${page}">
                                    <button type="submit" class="btn btn-link button-link">
                                        <i class="fa fa-edit">Изменить</i>
                                    </button>
                                </form>
                            </td>
                            <td>
                                <form th:action="@{/directions/delete/{id}(id=${direction.id})}" method="post">
                                    <input type="hidden" th:name="page" th:value="${page}">
                                    <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=${'directions'},
                                totalPages=${totalPages},
                                currentPage=${currentPage}) }" />
        </th:block>
    </main>
</body>

</html>