@model ZelWiki.Models.ViewModels.Admin.PageRevisionsViewModel
@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>
    关于页面 <a href="@GlobalConfiguration.BasePath/@sessionState.PageNavigation">@sessionState.Page.Name</a> 的修订
</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.Revisions.Count > 0)
    {
        <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
            <thead>
                <tr>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Revision")">修订好</a></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>
                    <td><strong>操作</strong></td>
                </tr>
            </thead>

            <tbody>
                @foreach (var h in Model.Revisions)
                {
                    <tr>
                        <td><a href="@GlobalConfiguration.BasePath/@sessionState.PageNavigation/@h.Revision" target="_blank" rel="noopener">@Html.DisplayTextFor(x => h.Revision)</a></td>
                        <td><a href="@GlobalConfiguration.BasePath/Profile/@h.ModifiedByUserName/Public">@Html.DisplayTextFor(x => h.ModifiedByUserName)</a></td>
                        <td>@Html.DisplayTextFor(x => h.ModifiedDate)</td>
                        <td>@Html.DisplayTextFor(x => h.ChangeSummary)</td>
                        <td>
                            @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateWarnLink(GlobalConfiguration.BasePath,
                                $"将{h.Name} 从 {h.HighestRevision} 回滚至 {h.Revision} 将会 {h.HigherRevisionCount} 个更改<br />"
                                + "还原并不意味着更改将丢失，但是还原过程将使用还原的更改创建新的修订.<br /><br />"
                                + "继续吗?",
                                "回滚", $"/Admin/RevertPageRevision/{h.Navigation}/{h.Revision}", Context.Request.Path.Value))

                            @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath, 
                                $"把 {h.Revision} 从 \"{h.Name}\" 的修订记录中删除,继续吗?",
                                "删除", $"/Admin/DeletePageRevision/{h.Navigation}/{h.Revision}", Context.Request.Path.Value))
                        </td>
                    </tr>
                }
            </tbody>
        </table>

        @Html.Raw(ZelWiki.Library.PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
    }
    else
    {
        <div class="d-flex small text-muted mb-0">
            <strong>
                The selected page does not have any revisions.
            </strong>
        </div>
    }
}
