@model IEnumerable<SportsDivision.Application.DTOs.ReportDtos.StudentsBySchoolReportDto>
@{
    ViewData["Title"] = "Students by School";
}

<div class="d-flex justify-content-between align-items-center mb-3">
    <h2 class="mb-0">Students by School</h2>
    <div class="d-flex gap-2">
        <a asp-action="StudentsBySchoolExcel" asp-route-tournamentId="@ViewBag.TournamentId" asp-route-schoolId="@ViewBag.SchoolId" asp-route-zoneId="@ViewBag.ZoneId" class="btn btn-success"><i class="bi bi-file-earmark-excel"></i> Export to Excel</a>
        <a asp-action="StudentsBySchoolPdf" asp-route-tournamentId="@ViewBag.TournamentId" asp-route-schoolId="@ViewBag.SchoolId" asp-route-zoneId="@ViewBag.ZoneId" class="btn btn-outline-danger"><i class="bi bi-file-earmark-pdf"></i> PDF</a>
    </div>
</div>
<hr />

@foreach (var school in Model)
{
    <div class="card shadow-sm mb-3">
        <div class="card-header bg-dark text-white">
            <h5 class="mb-0">@school.SchoolName <small class="text-muted">(@school.ZoneName)</small></h5>
        </div>
        <div class="card-body p-0">
            <table class="table table-hover mb-0">
                <thead><tr><th>Student</th><th>Sex</th><th>Events</th></tr></thead>
                <tbody>
                    @foreach (var s in school.Students)
                    {
                        <tr>
                            <td>@s.StudentName</td>
                            <td><span class="badge @(s.Sex == "Male" ? "bg-primary" : "bg-danger")">@s.Sex</span></td>
                            <td>@string.Join(", ", s.Events)</td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
}

<a asp-action="Index" class="btn btn-secondary">Back to Reports</a>
