@inject IJSRuntime Js

<div class="@(Back ? "" : "container") header">
    <div class="header-content @(Back ? "with-back" : "no-back")">
        @if (!SmallHeader)
        { 
            if (Back)
            {
                <div class="left-section">
                    <MudButton StartIcon="@(!Cancel ? Icons.Material.Outlined.ArrowBackIosNew : "")"
                               OnClick="@GoBack"
                               Color="Color.Info"
                               Style="text-transform: none"
                               Variant="Variant.Text">
                        @BackTo
                    </MudButton>
                </div>
            }

            <h3 class="page-title">@Title</h3>

            <div class="right-section">
                @if (!LabelSave.IsNullOrEmpty())
                {
                    <MudButton OnClick="@OnSave"
                               Color="Color.Info"
                               Style="text-transform: none"
                               Variant="Variant.Text">
                        @LabelSave
                    </MudButton>
                }
            </div>
        }
        else
        {
            <div class="title">
                <MudText Typo="Typo.h6">
                    <b>@Title</b>
                </MudText>
                <MudIconButton Icon="@Icons.Material.Rounded.Close" OnClick="@GoBack" />
            </div>
        }
    </div>
</div>

@code{
    [Parameter] public string? Title { get; set; }
    [Parameter] public bool Back { get; set; }
    [Parameter] public string BackTo { get; set; } = "";

    [Parameter] public EventCallback OnFilterToggle { get; set; }

    [Parameter] public bool Cancel { get; set; }
    [Parameter] public EventCallback OnCancel { get; set; }
    [Parameter] public string? LabelSave { get; set; }
    [Parameter] public EventCallback OnSave { get; set; }

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

    protected override void OnParametersSet()
    {
        Back = !Back ? !Back && Cancel : Back;
        BackTo = Cancel ? "Annulla" : BackTo;
    }

    private async Task GoBack()
    {
        if (Cancel)
        {
            await OnCancel.InvokeAsync();
            return;
        }

        await Js.InvokeVoidAsync("goBack");
    }

}