@page "/datainbox/{id:guid}"
@using DiunaBI.UI.Shared.Services
@using DiunaBI.Application.DTOModels
@using MudBlazor

<MudCard>
    <MudCardHeader>
        <CardHeaderContent>
            <MudText Typo="Typo.h5">Data Inbox Details</MudText>
        </CardHeaderContent>
        <CardHeaderActions>
            <MudButton Variant="Variant.Text" OnClick="GoBack" StartIcon="@Icons.Material.Filled.ArrowBack">Back to List</MudButton>
        </CardHeaderActions>
    </MudCardHeader>
    <MudCardContent>
        @if (isLoading)
        {
            <MudProgressLinear Color="Color.Primary" Indeterminate="true" />
        }
        else if (dataInbox == null)
        {
            <MudAlert Severity="Severity.Error">Data Inbox item not found</MudAlert>
        }
        else
        {
            <MudGrid>
                <MudItem xs="12" md="4">
                    <MudTextField @bind-Value="dataInbox.Name"
                                  Label="Name"
                                  Variant="Variant.Outlined"
                                  ReadOnly="true"
                                  FullWidth="true"/>
                </MudItem>
                <MudItem xs="12" md="4">
                    <MudTextField @bind-Value="dataInbox.Source"
                                  Label="Source"
                                  Variant="Variant.Outlined"
                                  ReadOnly="true"
                                  FullWidth="true"/>
                </MudItem>
                <MudItem xs="12" md="4">
                    <MudTextField Value="@dataInbox.CreatedAt.ToString("g")"
                                  Label="Created At"
                                  Variant="Variant.Outlined"
                                  ReadOnly="true"
                                  FullWidth="true"/>
                </MudItem>
            </MudGrid>

            <MudDivider Class="my-4"/>

            <MudText Typo="Typo.h6" Class="mb-2">Decoded Data</MudText>

            @if (string.IsNullOrEmpty(decodedData))
            {
                <MudAlert Severity="Severity.Info">No data available</MudAlert>
            }
            else if (hasDecodingError)
            {
                <MudAlert Severity="Severity.Error">Error decoding Base64 data</MudAlert>
                <MudPaper Class="pa-4 mt-2" Elevation="0">
                    <MudText Typo="Typo.body2" Style="font-family: monospace; white-space: pre-wrap; word-break: break-all;">@dataInbox.Data</MudText>
                </MudPaper>
            }
            else
            {
                <MudPaper Class="pa-4" Elevation="0" Style="background-color: #f5f5f5; max-height: 600px; overflow-y: auto;">
                    <MudText Typo="Typo.body2" Style="font-family: monospace; white-space: pre-wrap; word-break: break-word;">@decodedData</MudText>
                </MudPaper>
            }
        }
    </MudCardContent>
</MudCard>
