@using SteUp.Shared.Components.Layout
@using SteUp.Shared.Core.Dto
@using SteUp.Shared.Core.Interface.System
@inject IAttachedService AttachedService

<MudDialog Class="disable-safe-area">
    <DialogContent>
        <HeaderLayout SmallHeader="true" Cancel="true" OnCancel="@(() => MudDialog.Cancel())" Title="Aggiungi allegati"/>

        <div style="margin-bottom: 1rem;" class="content attached">
            <MudFab Size="Size.Small" Color="Color.Primary"
                    StartIcon="@Icons.Material.Rounded.CameraAlt"
                    Label="Camera" OnClick="@OnCamera"/>

            <MudFab Size="Size.Small" Color="Color.Primary"
                    StartIcon="@Icons.Material.Rounded.Image"
                    Label="Galleria" OnClick="@OnGallery"/>
        </div>
    </DialogContent>
</MudDialog>

@code {
    [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!;
    [Parameter] public bool CanAddPosition { get; set; }

    private List<AttachedDto>? Attached { get; set; }

    protected override void OnInitialized()
    {
        Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
    }

    private async Task OnCamera()
    {
        var selectImageFromCamera = await AttachedService.SelectImageFromCamera();

        if (selectImageFromCamera != null)
        {
            Attached ??= [];
            Attached.Add(selectImageFromCamera);
            MudDialog.Close(Attached);
        }
    }

    private async Task OnGallery()
    {
        Attached = await AttachedService.SelectImageFromGallery();

        if (Attached != null) MudDialog.Close(Attached);
    }
}