package speiger.src.coreengine.rendering.guiOld.helper.constrains;

import java.util.function.BooleanSupplier;

import speiger.src.coreengine.rendering.guiOld.GuiComponent;

public class ConditionalConstraint extends Constrain
{
	BooleanSupplier provider;
	Constrain[] target;
	
	public ConditionalConstraint(BooleanSupplier provider, Constrain... target)
	{
		this.provider = provider;
		this.target = target;
	}
	
	public static ConditionalConstraint parent(BooleanSupplier provider, float active, float inactive)
	{
		return new ConditionalConstraint(provider, new ParentConstrain(active * 0.5F), new ParentConstrain(inactive * 0.5F));
	}
	
	@Override
	public void apply()
	{
		target[provider.getAsBoolean() ? 1 : 0].apply();
	}
	
	@Override
	public void setComponents(GuiComponent owner, GuiComponent parent, Target target)
	{
		super.setComponents(owner, parent, target);
		for(int i = 0,m=this.target.length;i<m;i++)
		{
			this.target[i].setComponents(owner, parent, target);
		}
	}
	
}
