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

import java.util.function.BooleanSupplier;

import speiger.src.coreengine.math.misc.Facing;

public class Constraints
{
	public static ComponentConstrains getParentConstrains()
	{
		return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(), new ParentConstrain(), new ParentConstrain());
	}
	
	public static ComponentConstrains getParentConstrains(float padding)
	{
		return new ComponentConstrains(new ParentConstrain(padding), new ParentConstrain(padding), new ParentConstrain(padding), new ParentConstrain(padding));
	}
	
	public static ComponentConstrains getParentConstrains(float xPadding, float yPadding)
	{
		return new ComponentConstrains(new ParentConstrain(xPadding), new ParentConstrain(yPadding), new ParentConstrain(xPadding), new ParentConstrain(yPadding));
	}
	
	public static ComponentConstrains getParentConstrains(float xPadding, float yPadding, boolean unused)
	{
		return new ComponentConstrains(new ParentConstrain(xPadding), new ParentConstrain(yPadding), new ParentConstrain(xPadding * 0.5F), new ParentConstrain(yPadding * 0.5F));		
	}
	
	public static ComponentConstrains getParentConstrains(float xPadding, float yPadding, float widthPadding, float heightPadding)
	{
		return new ComponentConstrains(new ParentConstrain(xPadding), new ParentConstrain(yPadding), new ParentConstrain(widthPadding), new ParentConstrain(heightPadding));
	}
	
	public static ComponentConstrains getPixelConstrains(float x, float y, float width, float height)
	{
		return new ComponentConstrains(new PixelConstrain(x), new PixelConstrain(y), new PixelConstrain(width), new PixelConstrain(height));
	}
	
	public static ComponentConstrains getSideConstraint(float size, Facing side)
	{
		return getSideConstraint(size, side, 0F);
	}
	
	public static ComponentConstrains getSideConstraint(float size, Facing side, float offset)
	{
		switch(side)
		{
			case NORTH: return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(offset), new ParentConstrain(), new PixelConstrain(size));
			case EAST: return new ComponentConstrains(new ParentConstrain(size+offset).invert(), new ParentConstrain(), new PixelConstrain(size), new ParentConstrain());
			case SOUTH: return new ComponentConstrains(new ParentConstrain(), new ParentConstrain(size+offset).invert(), new ParentConstrain(), new PixelConstrain(size));
			case WEST: return new ComponentConstrains(new ParentConstrain(offset), new ParentConstrain(), new PixelConstrain(size), new ParentConstrain());
			default: return null;
		}
	}
	
	public static ComponentConstrains getScrollbarConstraints(BooleanSupplier supply, boolean horizontal, float barSize)
	{
		Constrain size = new PixelConstrain(barSize);
		Constrain bounds = new ConditionalConstraint(supply, new ParentConstrain(), new ParentConstrain(barSize / 2F));
		Constrain pos = new ParentConstrain(barSize).invert();
		Constrain fixedPos = new PixelConstrain();
		return horizontal ? new ComponentConstrains(fixedPos, pos, bounds, size) : new ComponentConstrains(pos, fixedPos, size, bounds);
	}
	
	public static ComponentConstrains getVerticalScrollbar(BooleanSupplier supply, float offset, float barSize)
	{
		return new ComponentConstrains(new ParentConstrain(barSize).invert(), new PixelConstrain(offset), new PixelConstrain(barSize), new ConditionalConstraint(supply, new ParentConstrain(offset / 2F), new ParentConstrain((barSize + offset) / 2F)));
	}
	
	public static Constrain createConditionalParent(BooleanSupplier supply, float activeSize, float deactiveSize)
	{
		return new ConditionalConstraint(supply, new ParentConstrain(activeSize / 2F), new ParentConstrain(deactiveSize / 2F));
	}
}
