@model TightWiki.Models.ViewModels.Admin.MissingPagesViewModel
@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>
    Missing Pages
</h3>

<p>
    Pages that have been linked to, but do not exist.<br /><br />
</p>

<td height="52" valign="middle" align="left">
    @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.Pages.Count > 0)
        {
            <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
                <thead>
                    <tr>
                        <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "SourcePage")">Source Page</a></strong></td>
                        <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "TargetPage")">Target Page</a></strong></td>
                    </tr>
                </thead>

                @foreach (var p in Model.Pages)
                {
                    <tr>
                        <td><a href="@GlobalConfiguration.BasePath/@p.SourcePageNavigation">@p.SourcePageName</a></td>
                        <td><a href="@GlobalConfiguration.BasePath/@p.TargetPageNavigation/Edit?Name=@p.TargetPageName">@p.TargetPageName</a></td>
                    </tr>
                }
            </table>

            @Html.Raw(TightWiki.Library.PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
        }
        else
        {
            <div class="d-flex small text-muted mb-0">
                <strong>
                    There are currently no missing pages being referenced by other wiki pages.
                </strong>
            </div>
        }
    }
