@page "/Error"
@layout MainLayout
@using System.Diagnostics
@using Microsoft.AspNetCore.Mvc
@attribute [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]

<PageTitle>Error - Something Went Wrong</PageTitle>

<MudContainer MaxWidth="MaxWidth.Medium" Class="d-flex align-center justify-center" Style="height: calc(100vh - 64px);">

    <div class="text-center">

        <MudIcon Icon="@Icons.Material.Filled.Error"
                 Size="Size.Large"
                 Color="Color.Error"
                 Class="mb-6" Style="font-size: 120px;" />

        <MudText Typo="Typo.h3" Class="mb-4 text-error">An Error Occurred</MudText>

        <MudText Typo="Typo.body1" Class="mb-6 text-muted">
            Sorry, an error occurred while processing your request.<br />
            Our team has been notified and is working to resolve the issue.
        </MudText>

        @if (ShowRequestId)
        {
            <MudPaper Elevation="1" Class="pa-4 mb-6 d-inline-block">
                <MudText Typo="Typo.subtitle2" Class="mb-2">
                    <strong>Request ID:</strong> <code>@RequestId</code>
                </MudText>
                <MudText Typo="Typo.caption" Class="text-muted">
                    Please provide this ID when contacting support to help us track the issue.
                </MudText>
            </MudPaper>
        }

        <MudButton Variant="Variant.Filled"
                   Color="Color.Primary"
                   Size="Size.Large"
                   Href="/"
                   StartIcon="@Icons.Material.Filled.Home">
            Back to Home
        </MudButton>

    </div>

</MudContainer>

@code {
    [CascadingParameter] private HttpContext? HttpContext { get; set; }

    private string? RequestId { get; set; }
    private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

    protected override void OnInitialized()
    {
        RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
    }
}