@inject NavigationManager Navigation
@inject IJSRuntime JS

<div class="page-header">
    <MudStack Spacing="0">
        <MudText Typo="Typo.h5">@Title</MudText>
        @if (!string.IsNullOrWhiteSpace(Subtitle))
        {
            <MudText Typo="Typo.body2" Class="mud-text-secondary">@Subtitle</MudText>
        }
    </MudStack>
    @if (ShowBack)
    {
        <MudButton Variant="Variant.Text" StartIcon="@Icons.Material.Filled.ArrowBack" OnClick="GoBack">بازگشت</MudButton>
    }
</div>

@code {
    [Parameter] public string Title { get; set; } = string.Empty;

    /// <summary>
    /// Optional subtitle text displayed below the title.
    /// </summary>
    [Parameter] public string? Subtitle { get; set; }
    
    /// <summary>
    /// Fallback URL if there's no browser history. Uses history.back() first.
    /// </summary>
    [Parameter] public string? BackHref { get; set; }

    /// <summary>
    /// Whether to show the back button. Default is true.
    /// </summary>
    [Parameter] public bool ShowBack { get; set; } = true;

    private async Task GoBack()
    {
        await JS.InvokeVoidAsync("history.back");
    }
}
