@model ZelWiki.Models.ViewModels.Admin.NamespacesViewModel
@using ZelWiki.Library
@using ZelWiki.Models
@{
    Layout = "/Views/Shared/_Layout.cshtml";
    var sessionState = ViewData["SessionState"] as ZelWiki.SessionState ?? throw new Exception("Wiki State Context cannot be null.");
}

<h3>
    命名空间
</h3>

<p>
    <br/><br/>
</p>

@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
    <div class="alert alert-danger">@Html.Raw(Model.ErrorMessage)</div>
}
@if (!string.IsNullOrEmpty(Model.SuccessMessage))
{
    <div class="alert alert-success">@Html.Raw(Model.SuccessMessage)</div>
}

@using (Html.BeginForm(null, null, FormMethod.Get, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
    @if (Model.Namespaces.Count > 0)
    {
        <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Name")">命名</a></strong></td>
                <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Pages")">包含页数</a></strong>
                </td>
            </tr>
            </thead>

            @foreach (var p in Model.Namespaces)
            {
                <tr>
                    <td>
                        <a href="@GlobalConfiguration.BasePath/Admin/Namespace/@(p.Namespace ?? string.Empty)">@(string.IsNullOrEmpty(p.Namespace) ? "(Default)" : p.Namespace)</a>
                    </td>
                    <td>@p.CountOfPages.ToString("N0")</td>
                </tr>
            }
        </table>

        @Html.Raw(ZelWiki.Library.PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
    }
    else
    {
        <div class="d-flex small text-muted mb-0">
            <strong>
                暂无数据
            </strong>
        </div>
    }
}
