<!DOCTYPE html>
<html lang="ru" xmlns:th="http://www.thymeleaf.org"
th:replace="~{layout/main :: html(pageTitle=${pageTitle}, activeMenu='groups', content=~{::content}, scripts=~{})}">
<body>
<th:block th:fragment="content">
<div class="card">
<div class="card-body">
<div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>
<div th:if="${subjects.isEmpty()}" class="alert alert-warning">
<i class="bi bi-exclamation-triangle me-2"></i>
Сначала добавьте хотя бы один предмет.
<a th:href="@{/subjects/new}">Добавить предмет</a>
</div>
<form th:action="${request.id != null} ? @{/groups/{id}/edit(id=${request.id})} : @{/groups/new}"
method="post" th:object="${request}" th:if="${!subjects.isEmpty()}">
<div class="row">
<div class="col-md-6 mb-3">
<label for="name" class="form-label">Название группы <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="name" th:field="*{name}"
th:classappend="${#fields.hasErrors('name')} ? 'is-invalid'"
placeholder="Группа А, Начинающие..." required>
<div class="invalid-feedback" th:if="${#fields.hasErrors('name')}" th:errors="*{name}"></div>
</div>
<div class="col-md-6 mb-3">
<label for="subjectId" class="form-label">Предмет <span class="text-danger">*</span></label>
<select class="form-select" id="subjectId" th:field="*{subjectId}"
th:classappend="${#fields.hasErrors('subjectId')} ? 'is-invalid'" required>
<option value="">Выберите предмет</option>
<option th:each="subject : ${subjects}" th:value="${subject.id}" th:text="${subject.name}"></option>
</select>
<div class="invalid-feedback" th:if="${#fields.hasErrors('subjectId')}" th:errors="*{subjectId}"></div>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="pricePerLesson" class="form-label">Цена за занятие (₽)</label>
<input type="number" class="form-control" id="pricePerLesson" th:field="*{pricePerLesson}"
placeholder="1500" min="0" step="50">
</div>
</div>
<div class="mb-3">
<label for="description" class="form-label">Описание</label>
<textarea class="form-control" id="description" th:field="*{description}" rows="3"
placeholder="Описание группы, уровень, расписание..."></textarea>
</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} ? @{/groups/{id}(id=${request.id})} : @{/groups}" class="btn btn-outline-secondary">
Отмена
</a>
</div>
</form>
</div>
</div>
</th:block>
</body>
</html>