@namespace ZB.MOM.WW.Theme
@* Components/TechButton.razor *@
<button @attributes="AdditionalAttributes" type="@Type" class="btn @VariantClass" disabled="@Busy">
    @if (Busy) { <span class="spinner-border spinner-border-sm me-1" aria-hidden="true"></span> }
    @ChildContent
</button>

@code {
    /// <summary>
    /// Visual variant, mapped to a Bootstrap <c>.btn-*</c> class.
    /// Defaults to <see cref="ButtonVariant.Primary"/>.
    /// </summary>
    [Parameter] public ButtonVariant Variant { get; set; } = ButtonVariant.Primary;

    /// <summary>HTML <c>type</c> attribute (<c>button</c>, <c>submit</c>, <c>reset</c>). Defaults to <c>button</c>.</summary>
    [Parameter] public string Type { get; set; } = "button";

    /// <summary>
    /// When <c>true</c>, disables the button and shows an inline spinner — use while an
    /// async action is in flight. Defaults to <c>false</c>.
    /// </summary>
    [Parameter] public bool Busy { get; set; }

    /// <summary>Button label content.</summary>
    [Parameter] public RenderFragment? ChildContent { get; set; }

    /// <summary>
    /// Arbitrary additional HTML attributes splatted onto the underlying
    /// <c>&lt;button&gt;</c> (e.g. <c>id</c>, <c>@onclick</c>, <c>name</c>, <c>value</c>).
    /// </summary>
    [Parameter(CaptureUnmatchedValues = true)] public IDictionary<string, object>? AdditionalAttributes { get; set; }

    private string VariantClass => Variant switch
    {
        ButtonVariant.Secondary => "btn-outline-secondary",
        ButtonVariant.Danger    => "btn-danger",
        ButtonVariant.Ghost     => "btn-link",
        _                       => "btn-primary",
    };
}
