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

<h3>
    Deleted Page Revisions
</h3>

<p>
    Page revision that have been deleted for the given page. These can be purged or restored.<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(TightWiki.Library.ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath,
    $"This will permanently purge all deleted pages revisions for \"{Model.Name}\". Continue?",
                  "Purge Deleted Revisions", $"/Admin/PurgeDeletedPageRevisions/{Model.PageId}", Context.Request.Path.Value))
<br />
<br />

@if (Model.Revisions.Count > 0)
{
    @using (Html.BeginForm(null, null, FormMethod.Get, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
    {
        <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
            <thead>
                <tr>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Revision")">Revision</a></strong></td>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "DeletedDate")">Deleted Date</a></strong></td>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "DeletedBy")">Deleted By</a></strong></td>
                    <td><strong>Action</strong></td>
                </tr>
            </thead>

            @foreach (var p in Model.Revisions)
            {
                <tr>
                    <td>
                        <a href="@GlobalConfiguration.BasePath/Admin/DeletedPageRevision/@p.Id/@p.Revision">@p.Revision</a>
                    </td>
                    <td>@p.DeletedDate</td>
                    <td>@p.DeletedByUserName</td>
                    <td>
                        @Html.Raw(TightWiki.Library.ConfirmActionHelper.GenerateSafeLink(GlobalConfiguration.BasePath,
                            "This will restore the deleted page and all of its history. Continue?",
                                 "Restore", $"/Admin/RestoreDeletedPageRevision/{p.Id}/{p.Revision}", Context.Request.Path.Value))

                        @Html.Raw(TightWiki.Library.ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath,
                            "This will permanently delete the specified page, all revisions and attachments. Continue?",
                                 "Purge", $"/Admin/PurgeDeletedPageRevision/{p.Id}/{p.Revision}", Context.Request.Path.Value))
                    </td>
                </tr>
            }
        </table>

        @Html.Raw(TightWiki.Library.PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
    }
}
