@using Bit.SharedWeb.Utilities
@model OrganizationUnassignedToProviderSearchViewModel

@{
    ViewData["Title"] = "Add Existing Organization";
    var providerId = ViewContext.RouteData.Values["id"];
}

<h1>Add Existing Organization</h1>
<div class="row mb-2">
    <div class="col">
        <form class="row g-3 align-items-center mb-2" method="get" asp-route-id="@providerId">
            <div class="col">
                <label class="visually-hidden" asp-for="OrganizationName"></label>
                <input type="text" class="form-control" placeholder="@Html.DisplayNameFor(m => m.OrganizationName)" asp-for="OrganizationName" name="name">
            </div>
            <div class="col">
                <label class="visually-hidden" asp-for="OrganizationOwnerEmail"></label>
                <input type="email" class="form-control" placeholder="@Html.DisplayNameFor(m => m.OrganizationOwnerEmail)" asp-for="OrganizationOwnerEmail" name="ownerEmail">
            </div>
            <div class="col-auto">
                <button type="submit" class="btn btn-primary" title="Search" formmethod="get"><i class="fa fa-search"></i> Search</button>
            </div>
        </form>
    </div>
</div>

<form method="post" id="select-form" asp-route-id="@providerId">
    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th style="width: 20px;">All</th>
                <th>Name</th>
                <th style="width: 190px;">Plan</th>
            </tr>
            </thead>
            <tbody>
            @if (!Model.Items.Any())
            {
                <tr>
                    <td colspan="5">No results to list.</td>
                </tr>
            }
            else
            {
                @for (var i = 0; i < Model.Items.Count; i++)
                {
                    <tr>
                        <td class="text-center">
                            @Html.HiddenFor(m => Model.Items[i].Id, new { @readonly = "readonly", autocomplete = "off" })
                            @Html.CheckBoxFor(m => Model.Items[i].Selected)
                        </td>
                        <td>@Html.ActionLink(Model.Items[i].DisplayName(), "Edit", "Organizations", new { id = Model.Items[i].Id }, new { target = "_blank" })</td>
                        <td>@(Model.Items[i].PlanType.GetDisplayAttribute()?.Name ?? Model.Items[i].PlanType.ToString())</td>
                    </tr>
                }
            }
            </tbody>
        </table>
    </div>
</form>

<div class="row">
    <div class="col">
        <nav>
            <ul class="pagination">
                @if (Model.PreviousPage.HasValue)
                {
                    <li class="page-item">
                        <a class="page-link" asp-action="AddExistingOrganization" asp-route-id="@providerId" asp-route-page="@Model.PreviousPage.Value"
                           asp-route-count="@Model.Count" asp-route-ownerEmail="@Model.OrganizationOwnerEmail"
                           asp-route-name="@Model.OrganizationName">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="AddExistingOrganization" asp-route-id="@providerId" asp-route-page="@Model.NextPage.Value"
                           asp-route-count="@Model.Count" asp-route-ownerEmail="@Model.OrganizationOwnerEmail"
                           asp-route-name="@Model.OrganizationName">Next</a>
                    </li>
                }
                else
                {
                    <li class="page-item disabled">
                        <a class="page-link" href="#" tabindex="-1">Next</a>
                    </li>
                }
            </ul>
        </nav>
    </div>
    <div class="col-auto">
        <button type="submit" class="btn btn-primary" form="select-form">Add to Reseller</button>
    </div>
</div>
