<!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="${departments.size()}">
            <h2 th:case="0">Данные отсутствуют</h2>
            <th:block th:case="*">
                <span class="mainSt">
                    <b>Кафедры</b>
                </span>
                <div>
                    <a href="/departments/edit/" class="btn btn-danger">Добавить кафедру</a>
                </div>
                <table class="table">
                    <caption></caption>
                    <thead>
                        <tr>
                            <th scope="col" class="w-10">ID</th>
                            <th scope="col" class="w-auto">Название</th>
                            <th scope="col" class="w-10"></th>
                            <th scope="col" class="w-10"></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="department : ${departments}">
                            <th scope="row" th:text="${department.id}"></th>
                            <td th:text="${department.name}"></td>
                            <td>
                                <form th:action="@{/departments/edit/{id}(id=${department.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="@{/departments/delete/{id}(id=${department.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>
    </main>
</body>

</html>