@namespace OpenArchival.Blazor.FileViewer

@implements IFileViewer
@using Microsoft.JSInterop
@using MudBlazor
@using OpenArchival.DataAccess
@inject IJSRuntime JSRuntime

<div style="width:100%; height: 1100px; max-height: 80vh; border: 1px solid var(--mud-palette-divider); border-radius: 4px; overflow: hidden; box-sizing: border-box;">
    <iframe src="@($"/api/files/{File.Id}")" style="width:100%; height:100%; border: none; display: block;" title="@File.OriginalName"></iframe>
</div>

@code {
    [Parameter]
    public required FilePathListing File { get; set; }

    [Parameter]
    public EventCallback<int> OnHeightMeasured { get; set; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            // We report 1100, but the CSS max-height: 80vh will cap it in the carousel
            await OnHeightMeasured.InvokeAsync(1100);
        }
    }
}
