@namespace Lumeo

<DropdownMenu @bind-Open="_open">
    <DropdownMenuTrigger @attributes="AdditionalAttributes">
        <Button Variant="Variant" Size="Size" Disabled="Disabled" Class="@CssClass">
            @if (ChildContent != null)
            {
                @ChildContent
            }
            else
            {
                @Text
            }
            <Blazicon Svg="Lucide.ChevronDown" Class="h-4 w-4 shrink-0 opacity-70 transition-transform duration-200 group-data-[state=open]:rotate-180" />
        </Button>
    </DropdownMenuTrigger>
    <DropdownMenuContent>
        @MenuContent
    </DropdownMenuContent>
</DropdownMenu>

@code {
    [Parameter] public string? Text { get; set; }
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public RenderFragment? MenuContent { get; set; }
    [Parameter] public Button.ButtonVariant Variant { get; set; } = Button.ButtonVariant.Default;
    [Parameter] public Button.ButtonSize Size { get; set; } = Button.ButtonSize.Default;
    [Parameter] public bool Disabled { get; set; }
    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private bool _open;

    private string CssClass => string.Join(" ", new[]
    {
        "gap-1.5",
        Class
    }.Where(s => !string.IsNullOrWhiteSpace(s)));
}
