@using System.Configuration;
@using SharpConnector.Models;
@using SharpConnector.Constants;
@using SharpConnector.Dtos;

@model Record<AddressBookDto>

@{
    bool isSupportDomainAddressBookEnabled =
        bool.TryParse(ConfigurationManager.AppSettings["SupportDomainAddressBook"], out var parsed) && parsed;
}

<div id="btn_wrapper">
    <div class="left">
        @if (isSupportDomainAddressBookEnabled)
        {
            <input type="button" value="Back" onclick="navigateTo('@Url.Action("Type", "AddressBook")');" />
        }
        else
        {
            <input type="button" value="Back" onclick="navigateTo('@Url.Action("Index", "Home")');" />
        }
    </div>
    <div id="title">
        <h3 class="text-center">@Session["AddrBookType"] Address Book</h3>
    </div>
    <div class="right">
    </div>
</div>

<div class="inner_wrapper stretch_to_bottom">
    @if (Model != null && Model.Pagination != null)
    {
        <table id="pagination" class="pagination" align="center" valign="top" cellspacing="0" cellpadding="0" border="0">
            <tr>
                <td align="left">
                    Showing <span id="startIndex">@Model.Pagination.StartIndex</span> to <span id="endIndex">@Model.Pagination.EndIndex</span> of <span id="totalRecords">@Model.Pagination.Total</span> records
                </td>
                <td width="33">
                    <button type="button" id="btn-left" class="btn-pagination disabled" onclick="navigateTo('@Url.Action("Index", "AddressBook")?page=@(Model.Pagination.Page - 1)&type=@Session["AddrBookType"]');"></button>
                </td>
                <td align="center" width="112">
                    <font size="3">
                        <span id="currentPage">@Model.Pagination.Page</span>/<span id="totalPage">@Model.Pagination.TotalPage</span> page
                    </font>
                </td>
                <td width="33">
                    <button type="button" id="btn-right" class="btn-pagination" onclick="navigateTo('@Url.Action("Index", "AddressBook")?page=@(Model.Pagination.Page + 1)&type=@Session["AddrBookType"]');"></button>
                </td>
            </tr>
        </table>
    }

    <table id="table_addrBook" class="tbl_content" align="center" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" border="1">
        <thead>
            <tr>
                <th>Folders</th>
            </tr>
        </thead>
        <tbody>
            @if (Model != null && Model.Records != null)
            {
                foreach (var m in Model.Records)
                {
                    <tr>
                        <td>
                            <a href="@Url.Action("Contacts", "AddressBook")?id=@m.AddressBookID&name=@HttpUtility.UrlEncode(m.AddressBookName)">
                                <img src="@Url.Content("~/Content/Images/folder.png")" height="24" width="24" border="0" hspace="2">
                                @m.AddressBookName
                            </a>
                        </td>
                    </tr>
                }
            }
            else
            {
                <tr>
                    <td><div class="no-records">@Msg.NoRecords</div></td>
                </tr>
            }
        </tbody>
    </table>
</div>