@inject IJSRuntime JS

@* ═══════════════════════════════════════════════
   EmptyState — Unified empty/not-found placeholder
   Usage: <EmptyState Title="سفارشی ثبت نشده" />
          <EmptyState Title="آدرسی یافت نشد"
                      Icon="@Icons.Material.Filled.LocationOff"
                      Description="ابتدا یک آدرس اضافه کنید."
                      ActionText="افزودن آدرس"
                      OnAction="OpenAddDialog" />
   ═══════════════════════════════════════════════ *@

<MudStack AlignItems="AlignItems.Center" Class="py-12" Spacing="3">
    <MudIcon Icon="@Icon" Size="Size.Large" Color="Color.Default"
             Class="mud-text-disabled" Style="font-size:3rem;" />
    <MudText Typo="Typo.h6" Class="mud-text-secondary">@Title</MudText>
    @if (!string.IsNullOrWhiteSpace(Description))
    {
        <MudText Typo="Typo.body2" Class="mud-text-secondary text-center"
                 Style="max-width:400px;">@Description</MudText>
    }
    @if (ChildContent is not null)
    {
        @ChildContent
    }
    else if (!string.IsNullOrWhiteSpace(ActionText))
    {
        @if (!string.IsNullOrWhiteSpace(ActionHref))
        {
            <MudButton Variant="Variant.Filled" Color="Color.Primary"
                       OnClick="GoBack" Class="mt-2">@ActionText</MudButton>
        }
        else
        {
            <MudButton Variant="Variant.Filled" Color="Color.Primary"
                       OnClick="OnAction" Class="mt-2">@ActionText</MudButton>
        }
    }
</MudStack>

@code {
    /// <summary>Material icon string.</summary>
    [Parameter] public string Icon { get; set; } = Icons.Material.Filled.Inbox;

    /// <summary>Main heading text.</summary>
    [Parameter] public string Title { get; set; } = "موردی یافت نشد";

    /// <summary>Optional secondary description.</summary>
    [Parameter] public string? Description { get; set; }

    /// <summary>Optional CTA button text.</summary>
    [Parameter] public string? ActionText { get; set; }

    /// <summary>If set, CTA becomes a link instead of callback.</summary>
    [Parameter] public string? ActionHref { get; set; }

    /// <summary>CTA button callback.</summary>
    [Parameter] public EventCallback OnAction { get; set; }

    /// <summary>Optional custom content (replaces ActionText button).</summary>
    [Parameter] public RenderFragment? ChildContent { get; set; }

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