using GraphicsManager.Enums;
using GraphicsManager.Interfaces;
using GraphicsManager.Objects;
using OpenTK.Mathematics;

namespace Luski.GUI.MainScreen.UI.Generic;

public class LuskiFlow : FlowLayout
{
    public override void ParentResize()
    {
        BlockDraw = true;
	    for (int i = 0; i < Controls.Length; i++)
	    {
		    if (Controls[i] is IParent parent)
		    {
			    parent.ParentResize();
		    }
	    }
	    if (Parent is not null) Parent.TryDraw();
	    BlockDraw = false;
    }
    
    public override void ReportSizeUpdate(IRenderObject Control)
    {
	    BlockDraw = true;
	    int index = Controls.IndexOf(Control);
	    if (index < Controls.Length - 1)
	    {
		    int dif = Control.Location.Y + Control.Size.Y - Controls[index + 1].Location.Y;
		    Vector2i v3i = new(0, dif);
		    for (int i = index + 1; i < Controls.Length; i++)
		    {
			    Controls[i].Location += v3i;
			    if (Controls[i] is IParent p)
			    {
				    p.ParentResize();
			    }
		    }
	    }
	    else
	    {
		    ForceScrollUpdate();
	    }
	    BlockDraw = false;
    }
}