<!DOCTYPE html>
<html lang="ru" xmlns:th="http://www.thymeleaf.org"
th:replace="~{layout/main :: html(pageTitle=${pageTitle}, activeMenu='schedule', content=~{::content}, scripts=~{})}">
<body>
<th:block th:fragment="content">
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>
<div th:if="${groups.isEmpty()}" class="alert alert-warning">
<i class="bi bi-exclamation-triangle me-2"></i>
Сначала создайте группу.
<a th:href="@{/groups/new}">Создать группу</a>
</div>
<form th:action="${request.id != null} ? @{/schedule/{id}/edit(id=${request.id})} : @{/schedule/new}"
method="post" th:object="${request}" th:if="${!groups.isEmpty()}">
<div class="row">
<div class="col-md-6 mb-3">
<label for="groupId" class="form-label">Группа <span class="text-danger">*</span></label>
<select class="form-select" id="groupId" th:field="*{groupId}"
th:classappend="${#fields.hasErrors('groupId')} ? 'is-invalid'" required>
<option value="">Выберите группу</option>
<option th:each="group : ${groups}" th:value="${group.id}"
th:text="${group.name} + ' (' + ${group.subjectName} + ')'"></option>
</select>
<div class="invalid-feedback" th:if="${#fields.hasErrors('groupId')}" th:errors="*{groupId}"></div>
</div>
<div class="col-md-6 mb-3">
<label for="date" class="form-label">Дата <span class="text-danger">*</span></label>
<input type="date" class="form-control" id="date" th:field="*{date}"
th:classappend="${#fields.hasErrors('date')} ? 'is-invalid'" required>
<div class="invalid-feedback" th:if="${#fields.hasErrors('date')}" th:errors="*{date}"></div>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="startTime" class="form-label">Начало <span class="text-danger">*</span></label>
<input type="time" class="form-control" id="startTime" th:field="*{startTime}"
th:classappend="${#fields.hasErrors('startTime')} ? 'is-invalid'" required>
<div class="invalid-feedback" th:if="${#fields.hasErrors('startTime')}" th:errors="*{startTime}"></div>
</div>
<div class="col-md-6 mb-3">
<label for="endTime" class="form-label">Окончание <span class="text-danger">*</span></label>
<input type="time" class="form-control" id="endTime" th:field="*{endTime}"
th:classappend="${#fields.hasErrors('endTime')} ? 'is-invalid'" required>
<div class="invalid-feedback" th:if="${#fields.hasErrors('endTime')}" th:errors="*{endTime}"></div>
</div>
</div>
<div class="mb-3">
<label for="topic" class="form-label">Тема занятия</label>
<input type="text" class="form-control" id="topic" th:field="*{topic}"
placeholder="Например: Введение в тригонометрию">
</div>
<div class="mb-3">
<label for="homework" class="form-label">Домашнее задание</label>
<textarea class="form-control" id="homework" th:field="*{homework}" rows="2"
placeholder="Задание для учеников..."></textarea>
</div>
<div class="mb-3">
<label for="notes" class="form-label">Заметки</label>
<textarea class="form-control" id="notes" th:field="*{notes}" rows="2"
placeholder="Заметки для себя..."></textarea>
</div>
<div class="mb-3" th:if="${request.id != null}">
<label for="status" class="form-label">Статус</label>
<select class="form-select" id="status" th:field="*{status}">
<option value="SCHEDULED">Запланировано</option>
<option value="COMPLETED">Проведено</option>
<option value="CANCELLED">Отменено</option>
</select>
</div>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary">
<i class="bi bi-check-lg me-1"></i> Сохранить
</button>
<a th:href="${request.id != null} ? @{/schedule/{id}(id=${request.id})} : @{/schedule}"
class="btn btn-outline-secondary">Отмена</a>
</div>
</form>
</div>
</div>
</div>
</div>
</th:block>
</body>
</html>