@namespace SufiChain.SufiBlazor.Components.Typography

@switch (Level)
{
    case 1:
        <h1 class="@CssClass" style="@Style" @attributes="AdditionalAttributes">@ChildContent</h1>
        break;
    case 2:
        <h2 class="@CssClass" style="@Style" @attributes="AdditionalAttributes">@ChildContent</h2>
        break;
    case 3:
        <h3 class="@CssClass" style="@Style" @attributes="AdditionalAttributes">@ChildContent</h3>
        break;
    case 4:
        <h4 class="@CssClass" style="@Style" @attributes="AdditionalAttributes">@ChildContent</h4>
        break;
    case 5:
        <h5 class="@CssClass" style="@Style" @attributes="AdditionalAttributes">@ChildContent</h5>
        break;
    case 6:
        <h6 class="@CssClass" style="@Style" @attributes="AdditionalAttributes">@ChildContent</h6>
        break;
    default:
        <h2 class="@CssClass" style="@Style" @attributes="AdditionalAttributes">@ChildContent</h2>
        break;
}

@code {
    /// <summary>
    /// Heading level (1-6).
    /// </summary>
    [Parameter]
    public int Level { get; set; } = 2;

    /// <summary>
    /// Visual size override (1-6). If not set, matches Level.
    /// </summary>
    [Parameter]
    public int? Size { get; set; }

    /// <summary>
    /// Text color.
    /// </summary>
    [Parameter]
    public SbColor Color { get; set; } = SbColor.Default;

    /// <summary>
    /// Text alignment.
    /// </summary>
    [Parameter]
    public SbTextAlign Align { get; set; } = SbTextAlign.Start;

    /// <summary>
    /// Whether to truncate text with ellipsis.
    /// </summary>
    [Parameter]
    public bool Truncate { get; set; }

    /// <summary>
    /// The content to render.
    /// </summary>
    [Parameter]
    public RenderFragment? ChildContent { get; set; }

    /// <summary>
    /// Additional CSS classes.
    /// </summary>
    [Parameter]
    public string? Class { get; set; }

    /// <summary>
    /// Inline styles.
    /// </summary>
    [Parameter]
    public string? Style { get; set; }

    /// <summary>
    /// Additional HTML attributes.
    /// </summary>
    [Parameter(CaptureUnmatchedValues = true)]
    public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private int VisualSize => Size ?? Level;

    private string CssClass
    {
        get
        {
            var classes = new List<string> { "sb-heading", $"sb-heading--h{VisualSize}" };

            if (Color != SbColor.Default)
            {
                classes.Add($"sb-heading--{Color.ToString().ToLowerInvariant()}");
            }

            if (Align != SbTextAlign.Start)
            {
                classes.Add($"sb-heading--align-{Align.ToString().ToLowerInvariant()}");
            }

            if (Truncate)
            {
                classes.Add("sb-heading--truncate");
            }

            if (!string.IsNullOrWhiteSpace(Class))
            {
                classes.Add(Class);
            }

            return string.Join(" ", classes);
        }
    }
}
