@model DashboardDto
@{
    ViewData["Title"] = "Dashboard";
    var tournaments = ViewBag.Tournaments as IEnumerable<TournamentDto>;
    var selectedTournamentId = ViewBag.SelectedTournamentId as int?;
}

<div class="d-flex justify-content-between align-items-center mb-4">
    <h2>Dashboard</h2>
    <form method="get" class="d-flex align-items-center gap-2">
        <label class="form-label mb-0 text-nowrap">Tournament:</label>
        <select name="tournamentId" class="form-select form-select-sm" style="width:250px" onchange="this.form.submit()">
            <option value="">-- All --</option>
            @if (tournaments != null)
            {
                @foreach (var t in tournaments)
                {
                    <option value="@t.TournamentId" selected="@(selectedTournamentId == t.TournamentId)">@t.Name</option>
                }
            }
        </select>
    </form>
</div>

<div class="row g-3 mb-4">
    <div class="col-md-3">
        <div class="card bg-primary text-white shadow-sm">
            <div class="card-body">
                <h6 class="card-title">Total Students</h6>
                <h2>@Model.TotalStudents</h2>
                <small>Male: @Model.MaleStudents | Female: @Model.FemaleStudents</small>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card bg-success text-white shadow-sm">
            <div class="card-body">
                <h6 class="card-title">Schools</h6>
                <h2>@Model.TotalSchools</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card bg-info text-white shadow-sm">
            <div class="card-body">
                <h6 class="card-title">Active Tournaments</h6>
                <h2>@Model.ActiveTournaments</h2>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="card bg-warning text-dark shadow-sm">
            <div class="card-body">
                <h6 class="card-title">Registrations</h6>
                <h2>@Model.TotalRegistrations</h2>
            </div>
        </div>
    </div>
</div>

@if (Model.TopSchools.Any())
{
    <div class="card shadow-sm">
        <div class="card-header" style="background-color: #003366; color: white;">
            <h5 class="mb-0">School Standings</h5>
        </div>
        <div class="card-body p-0">
            <table class="table table-striped table-hover mb-0">
                <thead class="table-dark">
                    <tr>
                        <th>#</th>
                        <th>School</th>
                        <th class="text-center">Points</th>
                        <th class="text-center">1st</th>
                        <th class="text-center">2nd</th>
                        <th class="text-center">3rd</th>
                    </tr>
                </thead>
                <tbody>
                    @for (int i = 0; i < Model.TopSchools.Count; i++)
                    {
                        var school = Model.TopSchools[i];
                        <tr>
                            <td><strong>@(i + 1)</strong></td>
                            <td>@school.SchoolName @(school.ShortName != null ? $"({school.ShortName})" : "")</td>
                            <td class="text-center"><strong>@school.TotalPoints</strong></td>
                            <td class="text-center">@school.FirstPlaceCount</td>
                            <td class="text-center">@school.SecondPlaceCount</td>
                            <td class="text-center">@school.ThirdPlaceCount</td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
}
