using System.Numerics;
using Voile.Rendering;

namespace Voile.UI.Containers;

/// <summary>
/// A horizontal container arranges its children horizontally, with a given horizontal spacing between child elements.
/// </summary>
public class HorizontalContainer : Container
{
    /// <summary>
    /// Horizontal spacing between child elements.
    /// </summary>
    public float Spacing { get; set; } = 16.0f;

    public HorizontalContainer(Rect minimumSize, List<UIElement> children, float spacing = 16.0f) : base(minimumSize, children)
    {
        Spacing = spacing;
    }

    public HorizontalContainer(float spacing = 16.0f)
    {
        Spacing = spacing;
    }

    public override void Arrange()
    {
        float currentX = 0.0f;

        for (int i = 0; i < Children.Count; i++)
        {
            var child = Children[i];
            var pos = new Vector2(currentX, 0.0f);
            child.LocalPosition = pos;

            currentX += child.Size.Width;

            if (i < Children.Count - 1)
            {
                currentX += Spacing;
            }
        }
    }
}