@namespace Lumeo
@inject Lumeo.Services.Localization.ILumeoLocalizer L

<div class="@CssClass" @attributes="AdditionalAttributes">
    <div class="flex items-center justify-between px-3 py-2 border-b border-border/40">
        @if (HeaderContent is not null)
        {
            @HeaderContent
        }
        else
        {
            <div class="flex items-center gap-2">
                <span class="font-medium text-sm">@Title</span>
                @if (Badge.HasValue)
                {
                    <span class="inline-flex items-center justify-center min-w-5 h-5 px-1.5 rounded-full bg-muted text-muted-foreground text-xs font-medium">
                        @Badge.Value
                    </span>
                }
            </div>
        }
    </div>

    <div class="flex-1 overflow-y-auto p-2 flex flex-col gap-2 min-h-16"
         @ondragover:preventDefault
         @ondrop="HandleDrop">
        @ChildContent
    </div>

    @if (AllowAdd)
    {
        <div class="p-2 border-t border-border/40">
            <button type="button"
                    class="w-full flex items-center gap-2 px-3 py-2 rounded-md text-sm text-muted-foreground hover:bg-muted/50 hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-[1.5px] focus-visible:ring-ring focus-visible:ring-offset-2"
                    @onclick="OnAdd">
                <Blazicon Svg="Lucide.Plus" class="h-3.5 w-3.5" />
                @L["Kanban.AddCard"]
            </button>
        </div>
    }
</div>

@code {
    [Parameter] public string? Title { get; set; }
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public int? Badge { get; set; }
    [Parameter] public RenderFragment? HeaderContent { get; set; }
    [Parameter] public bool AllowAdd { get; set; }
    [Parameter] public EventCallback OnAdd { get; set; }
    [Parameter] public EventCallback<DragEventArgs> OnDrop { get; set; }

    private async Task HandleDrop(DragEventArgs e) => await OnDrop.InvokeAsync(e);
    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private string CssClass => $"flex flex-col w-72 shrink-0 rounded-lg bg-muted/30 border border-border/40 max-h-full {Class}".Trim();
}
