<!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="${categories.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"></th>
                                        <th scope="col"></th>
                                    </tr>
                                </thead>
                                <tbody class="table-group-divider">
                                    <tr th:each="category : ${categories}">
                                        <th scope="row" th:text="${category.id}"></th>
                                        <td th:text="${category.name}"></td>
                                        <td>
                                            <form th:action="@{/admin/category/edit/{id}(id=${category.id})}" method="get">
                                                <button type="submit" class="btn btn-primary w-100">Редактировать</button>
                                            </form>
                                        </td>
                                        <td>
                                            <form th:action="@{/admin/category/delete/{id}(id=${category.id})}" method="post">
                                                <button type="submit" class="btn btn-primary w-100"
                                                    onclick="return confirm('Вы уверены?')">Удалить</button>
                                            </form>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="col-12 px-0">
                        <div class="block mb-4">
                            <a class="btn btn-primary" href="/admin/category/edit/">Добавить категорию</a>
                        </div>
                    </div>
                </div>
        
            </th:block>
    </main>
</body>

</html>