@namespace Lumeo

<div class="@CssClass"
     style="flex: @(Size.ToString("F2", System.Globalization.CultureInfo.InvariantCulture)) 1 0; min-width: 0; min-height: 0; overflow: auto;"
     @attributes="AdditionalAttributes">
    @ChildContent
</div>

@code {
    [CascadingParameter] public ResizablePanelGroup.ResizablePanelGroupContext Context { get; set; } = default!;
    [Parameter] public int Order { get; set; }
    [Parameter] public double DefaultSize { get; set; } = 50;
    [Parameter] public double MinSize { get; set; } = 10;
    [Parameter] public double MaxSize { get; set; } = 90;
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private double Size => Context?.GetPanelSize(Order) ?? DefaultSize;

    private string CssClass => $"relative {Class}".Trim();

    protected override void OnInitialized()
    {
        Context?.RegisterPanel?.Invoke(Order, MinSize, MaxSize);
    }
}
