@model IEnumerable<SchoolDto>
@{
    ViewData["Title"] = "Schools";
    var zones = ViewBag.Zones as IEnumerable<ZoneDto>;
    var selectedZone = ViewBag.SelectedZone as int?;
    var selectedLevel = ViewBag.SelectedLevel as string;
}

<div class="d-flex justify-content-between align-items-center mb-3">
    <h2>Schools</h2>
    <a asp-action="Create" class="btn btn-primary">Add School</a>
</div>

<form method="get" class="row g-2 mb-3">
    <div class="col-auto">
        <select name="zoneId" class="form-select form-select-sm">
            <option value="">All Zones</option>
            @if (zones != null) { @foreach (var z in zones) { <option value="@z.ZoneId" selected="@(selectedZone == z.ZoneId)">@z.Name</option> } }
        </select>
    </div>
    <div class="col-auto">
        <select name="level" class="form-select form-select-sm">
            <option value="">All Levels</option>
            <option value="Primary" selected="@(selectedLevel == "Primary")">Primary</option>
            <option value="Secondary" selected="@(selectedLevel == "Secondary")">Secondary</option>
            <option value="College" selected="@(selectedLevel == "College")">College</option>
        </select>
    </div>
    <div class="col-auto">
        <button type="submit" class="btn btn-sm btn-outline-primary">Filter</button>
    </div>
</form>

<partial name="_Notification" />

<table class="table table-striped table-hover">
    <thead class="table-dark">
        <tr>
            <th>Name</th>
            <th>Short Name</th>
            <th>Level</th>
            <th>Zone</th>
            <th>Students</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var school in Model)
        {
            <tr>
                <td>@school.Name</td>
                <td>@school.ShortName</td>
                <td><span class="badge bg-secondary">@school.SchoolLevel</span></td>
                <td>@school.ZoneName</td>
                <td>@school.StudentCount</td>
                <td>
                    <a asp-action="Edit" asp-route-id="@school.SchoolId" class="btn btn-sm btn-outline-primary">Edit</a>
                    <a asp-controller="Student" asp-action="Index" asp-route-schoolId="@school.SchoolId" class="btn btn-sm btn-outline-info">Students</a>
                </td>
            </tr>
        }
    </tbody>
</table>
