@model ExceptionsModel
@{
    var showActions = Current.User.Is(ExceptionsRoles.Admin);
}
@functions {
    public string ErrorStyle(StackExchange.Exceptional.Error e)
    {
        var ageHours = (DateTime.UtcNow - e.CreationDate).TotalHours;
        if (ageHours < 1)
        {
            return MonitorStatus.Critical.TextClass();
        }
        if (ageHours < 2)
        {
            return MonitorStatus.Warning.TextClass();
        }
        return null;
    }

    public string GetShortName(StackExchange.Exceptional.Error e)
    {
        const string trimEnd = "Exception";
        var lastName = e.Type.Split(StringSplits.Period_Plus).Last();
        if (lastName != trimEnd && lastName.EndsWith(trimEnd))
        {
            return lastName.Substring(0, lastName.Length - trimEnd.Length);
        }
        return lastName;
    }
}
@foreach (var e in Model.Errors)
{
    <tr class="js-error@(e.IsProtected ? " protected js-protected" : "")@(e.DeletionDate.HasValue ? " deleted js-deleted" : "")" data-id="@e.GUID" data-log="@e.ApplicationName">
        <td class="@(showActions ? null : " hidden")">
            <a title="@(e.DeletionDate.HasValue ? "Error is already deleted" : "Delete this error")" class="hover-pulsate js-delete-link@(e.DeletionDate.HasValue ? " disabled" : null)" href="~/exceptions/delete"><i class="fa fa-times text-danger" aria-hidden="true"></i></a>
            @if (e.DeletionDate.HasValue)
            {
                <a title="Undelete and protect this error" class="hover-pulsate text-warning js-protect-link" href="~/exceptions/protect"><i class="fa fa-lock fa-fw" aria-hidden="true"></i></a>
            }
            else if (!e.IsProtected)
            {
                <a title="Protect this error from automatic deletion" class="hover-pulsate text-warning js-protect-link" href="~/exceptions/protect"><i class="fa fa-lock fa-fw" aria-hidden="true"></i></a>
            }
            else
            {
                <i class="js-protected fa fa-lock text-primary fa-fw" aria-hidden="true" title="This error is protected"></i>
            }
            @if (Module.Settings.EnablePreviews)
            {
                <span class="js-preview">
                    <a href="~/exceptions/detail?id=@e.GUID&log=@e.ApplicationName.UrlEncode()&store=@Model.Store.Name.UrlEncode()"><i class="fa fa-eye" aria-hidden="true"></i></a>
                </span>
            }
        </td>
        <td class="@ErrorStyle(e)" data-val="@e.CreationDate.ToEpochTime()">@e.CreationDate.ToRelativeTimeSpanMini()</td>
        <td title="@e.Type">
            @if (Model.Log != null)
            {
                @GetShortName(e)
            }
            else
            {
                <a href="~/exceptions?log=@e.ApplicationName.UrlEncode()&store=@Model.Store.Name.UrlEncode()">@e.ApplicationName</a>
            }
        </td>
        <td>
            <a class="text-wordbreak js-exception-link @(e.Message.StartsWith("Failed to retrieve error log:") ? "bad-error" : null)" href="~/exceptions/detail?id=@e.GUID&log=@e.ApplicationName.UrlEncode()&store=@Model.Store.Name.UrlEncode()">
                @(e.Message.TruncateWithEllipsis(110))
            </a>
        </td>
        <td title="@e.UrlPath">@e.UrlPath.TruncateWithEllipsis(40)</td>
        <td>@e.IPAddress</td>
        <td>@e.Host</td>
        <td>@e.MachineName.ToLower()</td>
        <td data-count="@e.DuplicateCount">@Html.Raw(e.DuplicateCount > 1 ? "(" + e.DuplicateCount + "&times;)" : "")</td>
    </tr>
}   