@using salesbook.Shared.Core.Dto
@using salesbook.Shared.Components.Layout
@using salesbook.Shared.Core.Interface
@using salesbook.Shared.Components.Layout.Overlay
@inject IAttachedService AttachedService

<MudDialog Class="customDialog-form">
    <DialogContent>
        <HeaderLayout ShowProfile="false" 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.Image"
                    Label="Immagini" OnClick="OnImage"/>

            <MudFab Size="Size.Small" Color="Color.Primary"
                    StartIcon="@Icons.Material.Rounded.InsertDriveFile"
                    Label="File" OnClick="OnFile"/>
            
            @if (CanAddPosition)
            {
                <MudFab Size="Size.Small" Color="Color.Primary"
                        StartIcon="@Icons.Material.Rounded.AddLocationAlt"
                        Label="Posizione" OnClick="OnPosition"/>
            }
        </div>
    </DialogContent>
</MudDialog>

<SaveOverlay VisibleOverlay="VisibleOverlay" SuccessAnimation="SuccessAnimation"/>

@code {
    [CascadingParameter] private IMudDialogInstance MudDialog { get; set; }

    [Parameter] public bool CanAddPosition { get; set; }

    //Overlay for save
    private bool VisibleOverlay { get; set; }
    private bool SuccessAnimation { get; set; }

    private AttachedDTO? Attached { get; set; }

    protected override async Task OnInitializedAsync()
    {
        Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;

        _ = LoadData();
    }

    private async Task LoadData()
    {
    }

    private async Task Save()
    {
        VisibleOverlay = true;
        StateHasChanged();

        SuccessAnimation = true;
        StateHasChanged();

        await Task.Delay(1250);

        MudDialog.Close();
    }

    private async Task OnImage()
    {
        Attached = await AttachedService.SelectImage();
        MudDialog.Close(Attached);
    }

    private async Task OnFile()
    {
        Attached = await AttachedService.SelectFile();
        MudDialog.Close(Attached);
    }

    private async Task OnPosition()
    {
        Attached = await AttachedService.SelectPosition();
        MudDialog.Close(Attached);
    }

}