using System.Numerics;
using Voile.Rendering;

namespace Voile.UI.Containers;

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

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

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

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

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

            currentY += child.Size.Height;

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