<!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="@{/users/edit/{id}(id=${users.id},(page=${page}))}"
            th:object="${users}" 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="role" class="form-label">Роль</label>
                <input type="text" th:field="*{role}" id="role" class="form-control" readonly disabled>
            </div>
            <div class="mb-3">
                <label for="login" class="form-label">Логин</label>
                <input type="text" th:field="*{login}" id="login" class="form-control">
                <div th:if="${#fields.hasErrors('login')}" th:errors="*{login}" class="invalid-feedback"></div>
            </div>
            <div class="mb-3">
                <label for="password" class="form-label">Пароль</label>
                <input type="password" th:field="*{password}" id="password" class="form-control">
                <div th:if="${#fields.hasErrors('password')}" th:errors="*{password}" 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="" selected>Выберите кафедру</option>
                    <option th:each="departmentItem : ${departments}" th:value="${departmentItem.id}"
                        th:text="${departmentItem.name}" th:selected="${departmentId} == ${departmentItem.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="@{/users(page=${page})}">Отмена</a>
            </div>
        </form>
    </main>
</body>

</html>