<!DOCTYPE html>
<html lang="fr" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="fragments.html :: head(#{material.edit.title}, null)"></th:block>

    <style>
        table {
            margin: auto;
            text-align: left;
        }

        th, td {
            min-width: 100px;
        }
    </style>
</head>
<body>

<!-- Fragment de l'entête -->
<header th:include="fragments.html :: header(false)"></header>
<!-- Corps de la page -->
<section>
    <div th:include="fragments.html :: messages"></div>
    <h1 th:text="#{material.edit.title}"></h1>

    <table th:if="${!materials.empty}">
        <tr>
            <th th:text="#{keyword.material}"></th>
            <th th:text="#{keyword.type}"></th>
            <th></th>
        </tr>
        <tr th:each="material : ${materials}">
            <td class="materialCode" th:data-materialId="${material.id}"
                th:text="${material.name}"></td>
            <td th:text="${material.materialType.name}"></td>
            <td>
                <button class="editor" th:data-materialId="${material.id}" type="button"
                        th:text="#{keyword.edit}"></button>
            </td>
        </tr>
    </table>
    <b th:if="${materials.empty}" class="error" th:text="#{material.error.anyFound}"></b>
</section>
<!-- Fragment du pied de page -->
<footer th:include="fragments.html :: footer(null, true)"></footer>


<script>
    /*<![CDATA[*/
    (() => {
        $(".editor").on({
            click: function () {
                window.location.href = `/material/editor/${$(this).data("materialid")}`;
            }
        });
    })();
    /*]]>*/
</script>
</body>
</html>
