<!DOCTYPE html>
<html lang="ru" xmlns:th="http://www.thymeleaf.org"
th:replace="~{layout/main :: html(pageTitle='Расписание', activeMenu='schedule', content=~{::content}, scripts=~{})}">
<body>
<th:block th:fragment="content">
<!-- Навигация по неделям -->
<div class="d-flex justify-content-between align-items-center mb-4">
<div class="btn-group">
<a th:href="@{/schedule(date=${prevWeek})}" class="btn btn-outline-secondary">
<i class="bi bi-chevron-left"></i>
</a>
<a th:href="@{/schedule(date=${today})}" class="btn btn-outline-secondary">Сегодня</a>
<a th:href="@{/schedule(date=${nextWeek})}" class="btn btn-outline-secondary">
<i class="bi bi-chevron-right"></i>
</a>
</div>
<h5 class="mb-0">
<span th:text="${#temporals.format(weekStart, 'd MMM')}"></span> —
<span th:text="${#temporals.format(weekEnd, 'd MMM yyyy')}"></span>
</h5>
<a th:href="@{/schedule/new}" class="btn btn-primary">
<i class="bi bi-plus-lg me-1"></i> Добавить занятие
</a>
</div>
<div th:if="${success}" class="alert alert-success" th:text="${success}"></div>
<!-- Сетка расписания -->
<div class="row g-3">
<div class="col-12 col-lg" th:each="entry : ${weekLessons}">
<div class="card h-100" th:classappend="${entry.key.equals(today)} ? 'border-primary'">
<div class="card-header py-2" th:classappend="${entry.key.equals(today)} ? 'bg-primary text-white'">
<div class="fw-medium" th:text="${#temporals.format(entry.key, 'EEEE')}"></div>
<small th:text="${#temporals.format(entry.key, 'd MMMM')}"></small>
</div>
<div class="card-body p-2">
<div th:if="${entry.value.isEmpty()}" class="text-center text-muted py-3">
<small>Нет занятий</small>
</div>
<div th:each="lesson : ${entry.value}" class="lesson-card mb-2 p-2 rounded"
th:classappend="${lesson.status.name() == 'COMPLETED'} ? 'bg-success-subtle' : (${lesson.status.name() == 'CANCELLED'} ? 'bg-danger-subtle' : 'bg-light')">
<a th:href="@{/schedule/{id}(id=${lesson.id})}" class="text-decoration-none">
<div class="d-flex justify-content-between align-items-start">
<small class="text-muted" th:text="${#temporals.format(lesson.startTime, 'HH:mm')} + ' - ' + ${#temporals.format(lesson.endTime, 'HH:mm')}"></small>
<span class="badge"
th:classappend="${lesson.status.name() == 'COMPLETED'} ? 'bg-success' : (${lesson.status.name() == 'CANCELLED'} ? 'bg-danger' : 'bg-secondary')"
th:text="${lesson.studentCount}"></span>
</div>
<div class="fw-medium text-dark" th:text="${lesson.groupName}"></div>
<small class="text-primary" th:text="${lesson.subjectName}"></small>
<div th:if="${lesson.topic}" class="text-muted small text-truncate" th:text="${lesson.topic}"></div>
</a>
</div>
<a th:href="@{/schedule/new(date=${entry.key})}" class="btn btn-sm btn-outline-secondary w-100 mt-2">
<i class="bi bi-plus"></i>
</a>
</div>
</div>
</div>
</div>
</th:block>
</body>
</html>