@model AllServicesPaginationModel

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

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

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

    int maxPage = (int)Math.Ceiling((double)Model.TotalServicesCount /
        Model.ServicesPerPage);
}

<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="Service"
           asp-action="All"
           asp-route-currentPage="@previousPage"><<</a>
    </div>

    @{
        bool shouldNextPageBeDisabled = Model.CurrentPage == maxPage ||
        !Model.Services.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="Service"
           asp-action="All"
           asp-route-currentPage="@(Model.CurrentPage + 1)">>></a>
    </div>
</div>

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

<div class="row">
    @foreach (var house in Model.Services)
    {
        <partial name="_ServicePartial" model="@house" />
    }
</div>