@using Indotalent.Features.Serilogs.Database
@using MudBlazor

<MudDialog>
    <TitleContent>
        <MudText Typo="Typo.h6">
            <MudIcon Icon="@Icons.Material.Filled.BugReport" Class="mr-3 mb-n1" />
            Log Detail [#@Log.Id]
        </MudText>
    </TitleContent>
    <DialogContent>
        <MudContainer Style="max-height: 500px; overflow-y: scroll;" Class="pa-0">
            <MudGrid Spacing="1">
                <MudItem xs="12">
                    <MudText Typo="Typo.subtitle2" Color="Color.Primary">Message</MudText>
                    <MudAlert Severity="Severity.Normal" Variant="Variant.Outlined" NoIcon="true" Class="mud-width-full pa-2 mt-1">
                        @Log.Message
                    </MudAlert>
                </MudItem>

                @if (!string.IsNullOrEmpty(Log.Exception))
                {
                    <MudItem xs="12">
                        <MudText Typo="Typo.subtitle2" Color="Color.Error" Class="mt-2">Exception / Stack Trace</MudText>
                        <div style="background-color: #fef2f2; border: 1px solid #fee2e2; padding: 12px; font-family: monospace; font-size: 0.8rem; color: #991b1b; white-space: pre-wrap;">
                            @Log.Exception
                        </div>
                    </MudItem>
                }

                <MudItem xs="12">
                    <MudText Typo="Typo.subtitle2" Color="Color.Info" Class="mt-2">Properties (JSON Context)</MudText>
                    <div style="background-color: #f8fafc; border: 1px solid #e2e8f0; padding: 12px; font-family: monospace; font-size: 0.8rem; color: #334155; white-space: pre-wrap;">
                        @Log.Properties
                    </div>
                </MudItem>
            </MudGrid>
        </MudContainer>
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="Close" Variant="Variant.Text">Close</MudButton>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
    [Parameter] public GetSerilogLogsByIdResponse Log { get; set; } = default!;

    private void Close() => MudDialog.Close();
}