@model TightWiki.Models.ViewModels.Admin.ExceptionsViewModel
@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>
    Exceptions
</h3>

<p>
    Server and page exceptions.<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.GenerateWarnLink(GlobalConfiguration.BasePath,
    "This will permanently purge all exceptions. Continue?",
    "Purge Exceptions", "/Admin/PurgeExceptions", Context.Request.Path.Value))
<br />
<br />

@using (Html.BeginForm(null, null, FormMethod.Get, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
    @if (Model.Exceptions.Count > 0)
    {
        <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
            <thead>
                <tr>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Id")">Id</a></strong></td>
                    <td><strong>Text</strong></td>
                    <td><strong>Exception</strong></td>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "CreatedDate")">Date/Time</a></strong></td>
                </tr>
            </thead>

            @foreach (var ex in Model.Exceptions)
            {
                <tr>
                    <td><a href="@GlobalConfiguration.BasePath/Admin/Exception/@ex.Id">@ex.Id</a></td>
                    <td>@ex.Text</td>
                    <td>@ex.ExceptionText</td>
                    <td>@ex.CreatedDate</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>
                The exception log is currently empty.
            </strong>
        </div>
    }
}
