@namespace SufiChain.SufiBlazor.Components.Layout

<div class="sb-spacer @Class" style="@GetStyle()" aria-hidden="true"></div>

@code {
    /// <summary>
    /// Size preset.
    /// </summary>
    [Parameter]
    public SbSpacerSize Size { get; set; } = SbSpacerSize.Medium;
    
    /// <summary>
    /// Custom height (overrides Size).
    /// </summary>
    [Parameter]
    public string? Height { get; set; }
    
    /// <summary>
    /// Custom width (for horizontal spacing).
    /// </summary>
    [Parameter]
    public string? Width { get; set; }
    
    /// <summary>
    /// Whether the spacer should grow to fill available space.
    /// </summary>
    [Parameter]
    public bool Grow { get; set; }
    
    /// <summary>
    /// Additional CSS classes.
    /// </summary>
    [Parameter]
    public string? Class { get; set; }
    
    private string GetStyle()
    {
        var styles = new List<string>();
        
        if (Grow)
        {
            styles.Add("flex-grow: 1");
        }
        else if (!string.IsNullOrEmpty(Height))
        {
            styles.Add($"height: {Height}");
        }
        else
        {
            var height = Size switch
            {
                SbSpacerSize.ExtraSmall => "0.25rem",
                SbSpacerSize.Small => "0.5rem",
                SbSpacerSize.Medium => "1rem",
                SbSpacerSize.Large => "1.5rem",
                SbSpacerSize.ExtraLarge => "2rem",
                _ => "1rem"
            };
            styles.Add($"height: {height}");
        }
        
        if (!string.IsNullOrEmpty(Width))
        {
            styles.Add($"width: {Width}");
        }
        
        return string.Join("; ", styles);
    }
}
