LocalGovIMS_localgov-ims/src/Admin/Views/AccountHolder/List.cshtml
@using PagedList.Mvc
@using BusinessLogic.Extensions
@model Admin.Models.AccountHolder.ListViewModel

@{
    ViewBag.Title = "Account holders";
}

@section Header { Account holders }

@section Subheader {
    Find an account holder
    @if (!string.IsNullOrEmpty(Model.FundName))
    {
        <span>within fund '@Model.FundName'</span>
    }
}

@section Actions {
    @Html.ActionLink("Create account holder", "Create", new { }, new { @class = "btn btn-secondary" })
}

<h3 class="visually-hidden">Search criteria</h3>

<div class="border border-1 rounded p-2">
    @Html.Partial("_Search", Model.SearchCriteria)
</div>

<h3 class="visually-hidden">Search results</h3>

@if (Model.Items != null && Model.Items.Any())
{
    <div class="table-responsive">
        <table class="table table-striped table-bordered table-hover mt-2">
            <thead>
                <tr>
                    <th scope="col">Account reference</th>
                    <th scope="col">Account name</th>
                    <th scope="col">Address</th>
                    <th scope="col">Balance (£)</th>
                    <th scope="col"><span class="visually-hidden">Actions</span></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Items)
                {
                    <tr>
                        <td>@item.AccountReference</td>
                        <td>@item.FullNameAndTitle()</td>
                        <td>@item.Address()</td>
                        <td class="text-end @if ((item.CurrentBalance ?? 0) < 0) { @Html.Raw("td--negative") }">
                            @Html.ToCurrency(item.CurrentBalance)
                        </td>
                        <td class="text-end">
                            @Html.ActionLink("View", "Details", new { id = item.AccountReference }, new { @class = "btn btn-secondary" })
                            @Html.ActionLink("Edit", "Edit", new { id = item.AccountReference }, new { @class = "btn btn-secondary" })

                            @if (Model.SearchCriteria.IsAPaymentSearch)
                            {
                                @Html.ActionLink("Select", "SelectAccountReference", "Payment", new { id = item.AccountReference }, new { @class = "btn btn-secondary " })
                            }
                        </td>
                    </tr>
                }
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="5">
                        @if (Model.Pages > 1)
                        {
                            @Html.PagedListPager(Model.Items, page => Url.Action("Search", new
                            {
                                page = page,
                                FundCode = Model.SearchCriteria.FundCode,
                                AccountReference = Model.SearchCriteria.AccountReference,
                                HouseNumberName = Model.SearchCriteria.Address,
                                PostCode = Model.SearchCriteria.PostCode,
                                Surname = Model.SearchCriteria.Surname,
                            }))
                        }
                    </td>
                </tr>
            </tfoot>
        </table>
    </div>
}
else
{
    Html.RenderPartial("_NoResultsMessage", "account holders");
}

@section Scripts {
    @Scripts.Render("~/bundles/app/account-holders")
}
