@page
@model Pepegov.Identity.PL.Pages.Connect.SuperAdmin.SuperAdminLoginModel

<div class="row">
    <div>
        <table class="table table-hover table-striped table-bordered">
            <thead>
            <tr>
                <th scope="col">Id</th>
                <th scope="col">Login</th>
                <th scope="col">FIO</th>
                <th scope="col">Email</th>
                <th scope="col">Phone</th>
                <th scope="col">Count of access failed</th>
                <th scope="col">Lockout</th>
            </tr>
            </thead>
            <tbody>
            @foreach (var row in @Model.PagedUsers.Items)
            {
                <form method="post">
                    <tr onclick="this.form.submit()">
                        <td>
                            @row.Id
                            <input type="hidden" name="Id" asp-for="Input.Id" value="@row.Id"/>
                        </td>
                        <td>@row.UserName</td>
                        <td>@row.LastName @row.FirstName @row.MiddleName</td>
                        <td>@row.Email</td>
                        <td>@row.PhoneNumber</td>
                        <td>@row.AccessFailedCount</td>
                        <td>
                            @if (row.LockoutEnabled)
                            {
                                <p>false</p>
                            }
                            else
                            {
                                <p>@row.LockoutEnd.ToString()</p>
                            }
                        </td>
                        <td><input type="submit" value="LoginIn" /></td>
                    </tr>
                </form>
            }
            </tbody>
            
            <tfoot>
            <div class="d-flex flex-row">
                <div class="p-2">
                    <form method="get">
                        <input type="hidden" asp-for="ReturnUrl" value="@Model.ReturnUrl"/>
                        <select asp-for="PageSize" class="form-select" onchange="this.form.submit()" id="select_page_size">
                            @foreach (var item in Model.ListOfPageSize)
                            {
                                @if (item == Model.PageSize)
                                {
                                    <option selected>@item</option>
                                }
                                else
                                {
                                    <option value="@item">@item</option>
                                }
                            }
                        </select>
                        <input type="hidden" asp-for="PageIndex" value="0"/>
                    </form>
                </div>
                <div class="p-2">
                    <nav>
                        <ul class="pagination">
                            @if (Model.PagedUsers.HasPreviousPage)
                            {
                                <li class="page-item"><a asp-page="./Login" asp-route-ReturnUrl="@Model.ReturnUrl" asp-route-PageIndex="@Model.PreviousPageIndex" asp-route-PageSize="@Model.PageSize"  class="page-link">Previous</a></li>
                            }
                            else
                            {
                                <li class="page-item disabled"><a class="page-link">Previous</a></li>
                            }
                            @for (int i = 0; i < @Model.PagedUsers.TotalPages; i++)
                            {
                                if (Model.PageIndex == i)
                                {
                                    <li class="page-item disabled"><a class="page-link">@i</a></li>   
                                }
                                else
                                {
                                    <li class="page-item"><a asp-page="./Login" asp-route-ReturnUrl="@Model.ReturnUrl" asp-route-PageIndex="@i" asp-route-PageSize="@Model.PageSize" class="page-link">@i</a></li>
                                }
                            }
                            @if (Model.PagedUsers.HasNextPage)
                            {
                                <li class="page-item"><a asp-page="./Login" asp-route-ReturnUrl="@Model.ReturnUrl" asp-route-PageIndex="@Model.NextPageIndex" asp-route-PageSize="@Model.PageSize" class="page-link">Next</a></li>
                            }
                            else
                            {
                                <li class="page-item disabled"><a class="page-link">Next</a></li>
                            }
                        </ul>
                    </nav>
                </div>
            </div>
            </tfoot>
        </table>
    </div>
    
    @if (!string.IsNullOrEmpty(ViewData["Error"]?.ToString()))
    {
        <vc:snack-bar error-title="@ViewData["Error"]!.ToString()" error-description="@ViewData["ErrorTitle"]?.ToString()"></vc:snack-bar>
    }
    
</div>