@page
@using Iceshrimp.Backend.Core.Configuration
@using Iceshrimp.Backend.Core.Extensions
@using Iceshrimp.Backend.Core.Middleware
@using Microsoft.Extensions.Options
@model ErrorPageModel
@inject IOptions<Config.InstanceSection>         Instance
@inject IOptionsSnapshot<Config.SecuritySection> Security
@{
    // Not meant for direct consumption, use with RazorViewRenderService.
    Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>@($"Error {Model.Error.StatusCode} - Iceshrimp.NET")</title>
    @* ReSharper disable Html.PathError *@
    <link rel="stylesheet" href="~/Iceshrimp.Backend.styles.css"/>
    <link rel="stylesheet" href="~/css/default.css"/>
    <link rel="icon" type="image/png" href="~/_content/Iceshrimp.Assets.Branding/favicon.png"/>
    @* ReSharper restore Html.PathError *@
    <style>
        .footer {
            display: flex;
            justify-content: space-between;
            gap: 4px 8px;
            flex-wrap: wrap;
        }
    </style>
</head>
<body>
<h2>Error @Model.Error.StatusCode: @Model.Error.Error</h2>
@if (Model.Error.Message != null)
{
    <p>
        <strong>Message:</strong> @Model.Error.Message
    </p>
}
@if (Model.Error.Details != null)
{
    <p>
        <strong>Details:</strong> @Model.Error.Details
    </p>
}
@if (Model.Error.Errors is { Count: > 0 } errors)
{
    @foreach (var error in errors)
    {
        <strong>@error.Key</strong>
        <ul>
            @foreach (var val in error.Value)
            {
                <li>@val</li>
            }
        </ul>
    }
}
@if (Model.Error.Source != null)
{
    <p>
        <strong>Source:</strong>
        <code>@Model.Error.Source</code>
    </p>
}
<p>
    <strong>Request ID:</strong>
    <code>@Model.Error.RequestId</code>
</p>

@if (Security.Value.ExceptionVerbosity >= ExceptionVerbosity.Debug)
{
    <pre><code>@Model.Error.Exception.ToString()</code></pre>
}

<footer>
    <span class="footer">
        <span>
            <strong>Iceshrimp.NET</strong> v@(Instance.Value.Version)
        </span>
        @if (Model.Error.Exception is PublicPreviewDisabledException)
        {
            <a href="/login?rd=@(Request.Path.ToString().UrlEncode())">Login</a>
        }
    </span>
</footer>
</body>
</html>