@model ZelWiki.Models.ViewModels.Admin.DeletedPagesViewModel
@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>
    Deleted Pages
</h3>

<p>
    Pages that have been deleted. 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(ZelWiki.Library.ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath,
    "This will permanently purge all deleted pages. Continue?",
    "Purge Deleted Pages", "/Admin/PurgeDeletedPages", 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, "Page")">Page</a></strong></td>
                    <td><strong>Action</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/Admin/DeletedPage/@p.Id">@p.Title</a>
                    </td>
                    <td>
                        @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateSafeLink(GlobalConfiguration.BasePath, 
                            "This will restore the deleted page and all of its history. Continue?",
                            "Restore", "/Admin/RestoreDeletedPage/" + @p.Id, Context.Request.Path.Value))
                        @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateDangerLink(GlobalConfiguration.BasePath, 
                            "This will permanently delete the specified page, all revisions and attachments. Continue?",
                            "Purge", "/Admin/PurgeDeletedPage/" + @p.Id, Context.Request.Path.Value))
                    </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>
                Either the deleted pages queue is empty or your search criteria returned no results.
			</strong>
        </div>
    }
}

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