package visualization;

import java.awt.Graphics2D;
import java.awt.geom.Area;

import visualization.designs.*;

import background.systemVariables.ArrayVariable;
import background.systemVariables.SimpleVariable;
import background.systemVariables.TableVariable;

public class VisualComponent {
	
	public int x;
	public int y;
	public int height;
	public int width;
	public SimpleVariable variable;
	public ArrayVariable array;
	public TableVariable table;
	public Design dizajn;
	
	public Boolean name;
	public Boolean value;
	public Boolean border;
	
	public int defaultMultiplicator = 1;
	
	public VisualComponent(SimpleVariable var, int multiplicator) {		
		variable = var;
		defaultMultiplicator = multiplicator;
		reset();		
	}

	public VisualComponent(TableVariable var, int multiplicator) {		
		table = var;
		defaultMultiplicator = multiplicator;
		reset();		
	}
	public VisualComponent(ArrayVariable var, int multiplicator) {		
		array = var;
		defaultMultiplicator = multiplicator;
		reset();
	}
	
	public VisualComponent(SimpleVariable var) {		
		variable = var;				
		reset();		
	}

	public VisualComponent(TableVariable var) {		
		table = var;
		reset();		
	}

	public VisualComponent(ArrayVariable var) {		
		array = var;				
		reset();
	}
	
	public void reset() {
		dizajn = new DefaultDesign("");
		
		x = 0;
		y = 0;
		
		name = true;
		value = true;
		border = true;
		
		setMultiplicator(defaultMultiplicator);
	}
		
	public void setMultiplicator(int i) {
		dizajn.recalculateMultiplicator(i);
	}
	
	public int getWidthMultiplicator() {
		return Math.round(dizajn.vizWidth / dizajn.defWidth);
	}
	
	public int getHeightMultiplicator() {
		return Math.round(dizajn.vizHeight / dizajn.defHeight);
	}
	
	public void setDesign(String keyword, String color) {				
		switch (keyword) {
			case "simple": { dizajn = new SimpleDesign(color); break; }		
			default: {dizajn = new DefaultDesign(color); break;}
		}		
	}
	
	public void moveTo(int x, int y) {
		this.x = x+10;
		this.y = y+10;
	}
	
	public Area getBorder(Graphics2D g, Boolean draw) {
		return null;
	}

	public Area getNameShape(Graphics2D g, Boolean draw) {
		return null;
	}		

	public Area getValueShape(Graphics2D g, Boolean draw) {
		return null;
	}	
	
	public void initSize(Graphics2D g) {
		Area together = new Area();
		
		if (border) { Area s = getBorder(g, false); together.add(s);} 				
		if (value) { Area val = getValueShape(g, false); together.add(val);}		
		if (name) { Area name = getNameShape(g, false); together.add(name);}
				
		this.width = together.getBounds().width + 20;
		this.height = together.getBounds().height + 20;
	}	

	
	public void draw(Graphics2D g) {	
		if (border) getBorder(g, true); 		
		if (value) getValueShape(g, true);
		if (name) getNameShape(g, true);
	}
				
}
