namespace ZB.MOM.WW.Theme.Tests;

public class CommonControlsTests : TestContext
{
    [Theory]
    [InlineData(ButtonVariant.Primary, "btn-primary")]
    [InlineData(ButtonVariant.Secondary, "btn-outline-secondary")]
    [InlineData(ButtonVariant.Danger, "btn-danger")]
    [InlineData(ButtonVariant.Ghost, "btn-link")]
    public void TechButton_maps_variant(ButtonVariant v, string cls)
    {
        var cut = RenderComponent<TechButton>(p => p.Add(x => x.Variant, v).AddChildContent("Go"));
        var btn = cut.Find("button");
        Assert.Contains("btn", btn.ClassList);
        Assert.Contains(cls, btn.ClassList);
    }

    [Fact]
    public void TechButton_busy_disables_and_passes_through_attributes()
    {
        var cut = RenderComponent<TechButton>(p => p
            .Add(x => x.Busy, true)
            .AddUnmatched("id", "save")
            .AddChildContent("Save"));
        var btn = cut.Find("button");
        Assert.True(btn.HasAttribute("disabled"));
        Assert.Equal("save", btn.GetAttribute("id"));
    }

    [Fact]
    public void TechButton_not_busy_is_not_disabled()
    {
        var cut = RenderComponent<TechButton>(p => p.Add(x => x.Busy, false).AddChildContent("Go"));
        Assert.False(cut.Find("button").HasAttribute("disabled"));
    }

    [Fact]
    public void TechCard_renders_title_and_body()
    {
        var cut = RenderComponent<TechCard>(p => p
            .Add(x => x.Title, "Drivers")
            .AddChildContent("<div class='b'>x</div>"));
        Assert.Contains("Drivers", cut.Find(".panel-head").TextContent);
        Assert.NotNull(cut.Find(".panel-body .b"));
    }

    [Fact]
    public void TechField_renders_label_hint_error()
    {
        var cut = RenderComponent<TechField>(p => p
            .Add(x => x.Label, "Name")
            .Add(x => x.Hint, "required")
            .Add(x => x.Error, "missing")
            .AddChildContent("<input/>"));
        Assert.Contains("Name", cut.Find("label").TextContent);
        Assert.Contains("required", cut.Find(".form-text").TextContent);
        Assert.Contains("missing", cut.Find(".field-error").TextContent);
    }
}
