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

<p>
    The compilation statistics for all wiki page operations.<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, 
    "Purging the page compilation statistics will delete all of the stored compilation statistics for all pages. Continue?",
    "Purge Compilation Statistics", "/Admin/PurgeCompilationStatistics", Context.Request.Path.Value))
<br />
<br />

@if (Model.Statistics.Count > 0)
{
    <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Namespace")">Name</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "CreatedDate")">Date/Time</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Compilations")">Compilations</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgBuildTimeMs")">Duration</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgWikiMatches")">Matches</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "TotalErrorCount")">Errors</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgOutgoingLinkCount")">Links</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgTagCount")">Tags</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgRawBodySize")">Raw Size</a></strong></td>
            <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "AvgWikifiedBodySize")">Wikified Size</a></strong></td>
        </tr>

        @foreach (var stat in Model.Statistics)
        {

            <tr>
                <td>
                    @if (string.IsNullOrEmpty(@stat.Namespace) == false)
                    {
                        <text><a href="@GlobalConfiguration.BasePath/Admin/Namespace/@stat.Namespace">@stat.Namespace</a> :: </text>
                    } <a href="@GlobalConfiguration.BasePath/@stat.Navigation">@stat.Title</a>
                </td>
                <td>@stat.LatestBuild</td>
                <td>@stat.Compilations.ToString("N0")</td>
                <td>@stat.AvgBuildTimeMs.ToString("N0")ms</td>
                <td>@stat.AvgWikiMatches.ToString("N0")</td>
                <td>@stat.TotalErrorCount.ToString("N0")</td>
                <td>@stat.AvgOutgoingLinkCount.ToString("N0")</td>
                <td>@stat.AvgTagCount.ToString("N0")</td>
                <td>@NTDLS.Helpers.Formatters.FileSize((long)stat.AvgRawBodySize)</td>
                <td>@NTDLS.Helpers.Formatters.FileSize((long)stat.AvgWikifiedBodySize)</td>
            </tr>
        }
    </table>

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