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

<head>
    <title>Редактировать направление</title>
</head>

<body>
    <main layout:fragment="content">
        <form action="#" th:action="@{/directions/edit/{id}(id=${directions.id},(page=${page}))}"
            th:object="${directions}" method="post">
            <div class="mb-3">
                <label for="id" class="form-label">ID</label>
                <input type="text" th:value="*{id}" id="id" class="form-control" readonly disabled>
            </div>
            <div class="mb-3">
                <label for="name" class="form-label">Направление</label>
                <input type="text" th:field="*{name}" id="name" class="form-control">
                <div th:if="${#fields.hasErrors('name')}" th:errors="*{name}" class="invalid-feedback"></div>
            </div>
            <div class="mb-3">
                <label for="code" class="form-label">Код</label>
                <input type="text" th:field="*{code}" id="code" class="form-control">
                <div th:if="${#fields.hasErrors('code')}" th:errors="*{code}" class="invalid-feedback">
                </div>
            </div>
            <div class="mb-3">
                <label for="things" class="form-label">Предметы ЕГЭ</label>
                <input type="text" th:field="*{things}" id="things" class="form-control">
                <div th:if="${#fields.hasErrors('things')}" th:errors="*{things}" class="invalid-feedback">
                </div>
            </div>
            <div class="mb-3">
                <label for="departmentId" class="form-label">Кафедра</label>
                <select th:field="*{departmentId}" id="departmentId" class="form-control">
                    <option th:if="*{departmentId} == null" value="">Выберите кафедру</option>
                    <option th:unless="*{departmentId} == null" th:value="*{departmentId}" th:text="*{name}"></option>
                    <option th:each=" department : ${departments}" th:value="${department.id}"
                        th:text="${department.name}" th:selected="*{departmentId} == ${department.id}">
                    </option>
                </select>
                <div th:if="${#fields.hasErrors('departmentId')}" th:errors="*{departmentId}" class="invalid-feedback">
                </div>
            </div>
            <div class="mb-3 d-flex flex-row">
                <button class="btn btn-primary me-2 button-fixed-width" type="submit">Сохранить</button>
                <a class="btn btn-secondary button-fixed-width" th:href="@{/directions(page=${page})}">Отмена</a>
            </div>
        </form>
    </main>
</body>

</html>