@model AllDoctorsQueryModel

@{
    ViewBag.Title = "All Doctors";
}

<h2 class="text-center">@ViewBag.Title</h2>
<hr />

<form method="get">
    <div class="row">
        <div class="form-group col-md-3 d-flex justify-content-between">
            <div class="form-group">
                <label asp-for="Specialty"></label>
                <select asp-for="Specialty" class="form-control">
                    <option value="">All</option>
                    @foreach (var category in Model.Specialities)
                    {
                        <option value="@category">@category</option>
                    }
                </select>
            </div>
            <div class="form-group">
                <label asp-for="DoctorsPerPage"></label>
                <select asp-for="DoctorsPerPage" class="form-control">
                    <option value="3">3</option>
                    <option value="6">6</option>
                    <option value="9">9</option>
                </select>
            </div>
        </div>

        <div class="form-group col-md-3">
            <label asp-for="SearchTerm"></label>
            <input asp-for="SearchTerm" class="form-control" placeholder="...">
        </div>


        <div class="col-md-3">
            <div class="form-group mt-4 p-2">
                <input type="submit" value="Search" class="btn btn-primary" />
            </div>
        </div>
    </div>
</form>


@{
    int previousPage = Model.CurrentPage - 1;
    if (previousPage < 1)
    {
        previousPage = 1;
    }

    int maxPage = (int)Math.Ceiling((double)Model.TotalDoctorsCount /
        Model.DoctorsPerPage);
}

<div class="row mb-5">
    <div class="col-md-6 d-grid gap-2 d-md-flex justify-content-md-start">
        <a class="btn btn-primary @(Model.CurrentPage == 1 ? "disabled" : string.Empty)"
           asp-controller="Doctor"
           asp-action="All"
           asp-route-currentPage="@previousPage"
           asp-route-category="@Model.Specialty"
           asp-route-searchTerm="@Model.SearchTerm"><<</a>
    </div>

    @{
        bool shouldNextPageBeDisabled = Model.CurrentPage == maxPage ||
        !Model.Doctors.Any();
    }

    <div class="col-md-6 d-grid gap-2 d-md-flex justify-content-md-end">
        <a class="btn btn-primary
           @(shouldNextPageBeDisabled ? "disabled" : string.Empty)"
           asp-controller="Doctor"
           asp-action="All"
           asp-route-currentPage="@(Model.CurrentPage + 1)"
           asp-route-category="@Model.Specialty"
           asp-route-searchTerm="@Model.SearchTerm">>></a>
    </div>
</div>

@if (!Model.Doctors.Any())
{
    <h2 class="text-center">No houses found by the given criteria!</h2>
}

<div class="row">
    @foreach (var doctor in Model.Doctors)
    {
        <partial name="_DoctorPartial" model="@doctor" />
    }
</div>
