@model ProvidersModel
@{
    ViewData["Title"] = "Providers";
}

<h1>Providers</h1>

<div class="row mb-2">
    <div class="col">
        <form class="form-inline mb-2" method="get">
            <label class="sr-only" asp-for="Name">Name</label>
            <input type="text" class="form-control mb-2 mr-2" placeholder="Name" asp-for="Name" name="name">
            <label class="sr-only" asp-for="UserEmail">User email</label>
            <input type="text" class="form-control mb-2 mr-2" placeholder="User email" asp-for="UserEmail" name="userEmail">
            <button type="submit" class="btn btn-primary mb-2" title="Search"><i class="fa fa-search"></i> Search</button>
        </form>
    </div>
    <div class="col-auto">
        <a asp-action="Create" class="btn btn-secondary">Create Provider</a>
    </div>
</div>

<div class="table-responsive">
    <table class="table table-striped table-hover">
        <thead>
            <tr>
                <th>Name</th>
                <th style="width: 190px;">Status</th>
                <th style="width: 150px;">Created</th>
            </tr>
        </thead>
        <tbody>
            @if(!Model.Items.Any())
            {
                <tr>
                    <td colspan="5">No results to list.</td>
                </tr>
            }
            else
            {
                @foreach(var provider in Model.Items)
                {
                    <tr>
                        <td>
                            <a asp-action="@Model.Action" asp-route-id="@provider.Id">@(provider.Name ?? "Pending")</a>
                        </td>
                        <td>@provider.Status</td>
                        <td>
                            <span title="@provider.CreationDate.ToString()">
                                @provider.CreationDate.ToShortDateString()
                            </span>
                        </td>
                    </tr>
                }
            }
        </tbody>
    </table>
</div>

<nav>
    <ul class="pagination">
        @if(Model.PreviousPage.HasValue)
        {
            <li class="page-item">
                <a class="page-link" asp-action="Index" asp-route-page="@Model.PreviousPage.Value"
                   asp-route-count="@Model.Count" asp-route-userEmail="@Model.UserEmail"
                   asp-route-name="@Model.Name" asp-route-paid="@Model.Paid">Previous</a>
            </li>
        }
        else
        {
            <li class="page-item disabled">
                <a class="page-link" href="#" tabindex="-1">Previous</a>
            </li>
        }
        @if(Model.NextPage.HasValue)
        {
            <li class="page-item">
                <a class="page-link" asp-action="Index" asp-route-page="@Model.NextPage.Value"
                   asp-route-count="@Model.Count" asp-route-userEmail="@Model.UserEmail"
                   asp-route-name="@Model.Name" asp-route-paid="@Model.Paid">Next</a>
            </li>
        }
        else
        {
            <li class="page-item disabled">
                <a class="page-link" href="#" tabindex="-1">Next</a>
            </li>
        }
    </ul>
</nav>
