@namespace Lumeo

@if (ForceMount || IsOpen)
{
    <div class="@CssClass" hidden="@(IsOpen ? null : "hidden")" @attributes="AdditionalAttributes">
        <div class="pb-4 pt-0">
            @ChildContent
        </div>
    </div>
}

@code {
    [CascadingParameter] public Accordion.AccordionContext Context { get; set; } = default!;
    [CascadingParameter] public AccordionItem.AccordionItemContext ItemContext { get; set; } = default!;
    [Parameter] public RenderFragment? ChildContent { get; set; }

    /// <summary>
    /// When true, this panel is always rendered into the DOM (with the
    /// <c>hidden</c> attribute when closed) instead of being unmounted.
    /// Use when child state (form inputs, scroll position, expensive
    /// component init) must survive closing the accordion item.
    /// Default <c>false</c> preserves the original unmount behaviour.
    /// </summary>
    [Parameter] public bool ForceMount { get; set; }

    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private bool IsOpen => Context.IsOpen(ItemContext.Value);

    private string CssClass => $"overflow-hidden text-sm {(IsOpen ? "animate-accordion-down" : "")} {Class}".Trim();
}
