@model ZelWiki.Models.ViewModels.Admin.PagesViewModel
@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>
}

@Html.Raw(ConfirmActionHelper.GenerateWarnLink(GlobalConfiguration.BasePath,
        "这将重建wiki中的所有页面,这可能需要一些时间. 继续吗?",
    "重新构建所有页面", "/Admin/RebuildAllPages", Context.Request.Path.Value))

@Html.Raw(ConfirmActionHelper.GenerateWarnLink(GlobalConfiguration.BasePath,
            "这将编译wiki中的所有页面并将其存储在缓存中,这可能需要一些时间. 继续吗?",
    "重新缓存页面", "/Admin/PreCacheAllPages", Context.Request.Path.Value))

@Html.Raw(ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath, 
        "这将将删除所有页面和页面附件的所有修订历史记录,只保留最新版本。危险动作!!!继续吗?",
        "截断页面修订", "/Admin/TruncatePageRevisions", Context.Request.Path.Value))
<br />
<br />

@using (Html.BeginForm(null, null, FormMethod.Get, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
    <div class="container">
        <div class="d-flex justify-content-end mb-4">
            <div class="flex-grow-1 me-2">
                @Html.TextBoxFor(x => x.SearchString, new { @class = "form-control" })
            </div>
            <button type="submit" class="btn btn-primary">Search</button>
        </div>
    </div>
    <br />

    @if (Model.Pages.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, "Revision")">修订号</a></strong></td>
                    <td><strong>删除版本</strong></td>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "ModifiedBy")">修改人</a></strong></td>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "ModifiedDate")">修改时间</a></strong></td>
                    <td><strong>操作</strong></td>
                </tr>
            </thead>

            @foreach (var p in Model.Pages)
            {
                <tr>
                    <td>
                        @if (string.IsNullOrEmpty(@p.Namespace) == false)
                        {
                            <text><a href="@GlobalConfiguration.BasePath/Admin/Namespace/@p.Namespace">@p.Namespace</a> :: </text>
                        } <a href="@GlobalConfiguration.BasePath/@p.Navigation">@p.Title</a>
                    </td>
                    <td><a href="@GlobalConfiguration.BasePath/Admin/PageRevisions/@p.Navigation">@p.Revision</a></td>
                    <td><a href="@GlobalConfiguration.BasePath/Admin/DeletedPageRevisions/@p.Id">@p.DeletedRevisionCount</a></td>
                    <td>@p.ModifiedByUserName</td>
                    <td>@p.ModifiedDate</td>
                    <td>
                        @Html.Raw(ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath, 
                            $"即将删除 \"{p.Name}\" , 总共 {p.Revision} 个修订版和附件将移入删除队列无法恢复.继续吗?",
                            "删除", "/Admin/DeletePage/" + @p.Id, Context.Request.Path.Value))
                    </td>
                </tr>
            }
        </table>

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

<script>
    window.onload = function () {
        document.getElementById("SearchString").focus();
    }
</script>
