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

import java.util.List;

import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectList;

public class ParentBox implements IGuiBox
{
	ObjectList<IGuiBox> children = new ObjectArrayList<>();
	IGuiBox parent;
	
	float minX;
	float minY;
	float maxX;
	float maxY;
	
	public ParentBox(float value) {
		minX = value;
		minY = value;
		maxX = -value;
		maxY = -value;
	}
	
	public ParentBox(float paddingTop, float paddingLeft, float paddingBottom, float paddingRight) {
		minX = paddingLeft;
		minY = paddingTop;
		maxX = paddingRight;
		maxY = paddingBottom;
	}
	
	@Override
	public IGuiBox addChild(IGuiBox box) {
		children.add(box);
		box.setParent(this);
		return this;
	}
	
	@Override
	public IGuiBox removeChild(IGuiBox box) {
		if(children.remove(box)) box.setParent(null);
		return this;
	}
	
	@Override
	public IGuiBox clearChildren() {
		for(int i = 0,m=children.size();i<m;i++) {
			children.get(i).setParent(null);
		}
		children.clear();
		return this;
	}
	
	@Override
	public List<IGuiBox> children() {
		return children.unmodifiable();
	}
	
	@Override
	public IGuiBox onChanged() {
		for(int i = 0,m=children.size();i<m;i++) {
			children.get(i).onChanged();
		}
		return this;
	}
	
	@Override
	public IGuiBox setParent(IGuiBox box) {
		parent = box;
		return this;
	}
	
	@Override
	public IGuiBox getParent() { return parent; }
	@Override
	public float getScale() { return parent.getScale(); }
	@Override
	public float getBaseX() { return minX + parent.getBaseX(); }
	@Override
	public float getBaseY() { return minY + parent.getBaseY(); }
	@Override
	public float getRelativeX() { return minX + parent.getRelativeX(); }
	@Override
	public float getRelativeY() { return minY + parent.getRelativeY(); }
	@Override
	public float getWidth() { return parent.getWidth(maxX - minX); }
	@Override
	public float getWidth(float extra) { return parent.getWidth((maxX - minX) + extra); }
	@Override
	public float getHeight() { return parent.getHeight(maxY - minY); }
	@Override
	public float getHeight(float extra) { return parent.getHeight((maxY - minY) + extra); }
	@Override
	public float getMinX() { return parent.getMinX(minX); }
	@Override
	public float getMinX(float extra) { return parent.getMinX(minX + extra); }
	@Override
	public float getMinY() { return parent.getMinY(minY); }
	@Override
	public float getMinY(float extra) { return parent.getMinY(minY + extra); }
	@Override
	public float getMaxX() { return parent.getMaxX(maxX); }
	@Override
	public float getMaxX(float extra) { return parent.getMaxX(maxX + extra); }
	@Override
	public float getMaxY() { return parent.getMaxY(maxY); }
	@Override
	public float getMaxY(float extra) { return parent.getMaxY(maxY + extra); }
	@Override
	public float getCenterX() { return parent.getCenterX((maxX - minX) * 0.5F); } 
	@Override
	public float getCenterX(float extra) { return parent.getCenterX((maxX - minX) * 0.5F + extra); }
	@Override
	public float getCenterY() { return parent.getCenterY((maxY - minY) * 0.5F); }
	@Override
	public float getCenterY(float extra) { return parent.getCenterY((maxY - minY) * 0.5F + extra); }
	@Override
	public IGuiBox setX(float x) { throw new UnsupportedOperationException(); }
	@Override
	public IGuiBox setY(float y) { throw new UnsupportedOperationException(); }
	@Override
	public IGuiBox setWidth(float width) { throw new UnsupportedOperationException(); }
	@Override
	public IGuiBox setHeight(float height) { throw new UnsupportedOperationException(); }
	@Override
	public IGuiBox setScale(float scale) { throw new UnsupportedOperationException(); }
	@Override
	public IGuiBox move(float xOffset, float yOffset) { throw new UnsupportedOperationException(); }
	@Override
	public IGuiBox resize(float xGrowth, float yGrowth) { throw new UnsupportedOperationException(); }
	@Override
	public IGuiBox scale(float scale) { throw new UnsupportedOperationException(); }
	@Override
	public float getBaseScale() { return 1F; }
	@Override
	public float getBaseWidth() { return parent.getBaseWidth() + (maxX - minX); }
	@Override
	public float getBaseHeight() { return parent.getBaseHeight() + (maxY - minY); }
}
