package background.commands;

import visualization.VisualPanel;
import background.CommandManager;
import background.expressions.MathTree;
import background.systemVariables.ArrayVariable;
import background.systemVariables.SimpleVariable;
import background.systemVariables.TableVariable;

public class VariableCommand extends Command {
	public String type;
	public String name;
	public Boolean array = false;	
	public Boolean table = false;
	public MathTree size;
	public MathTree size2;	
	public VisualPanel visualPanel;
	public int posun = 0;
	public int posun2 = 0;
	public int sizeNumber;
	public int sizeNumber2;
	
	public VariableCommand(Boolean viz, CommandManager cm) { super(viz, cm); visualPanel = commandManager.visualPanel;}
	public VariableCommand(CommandManager cm) { super(cm);}
		
	@Override
	public String getType() {
		return "Variable";
	}
	
	public void setSize(String s) {
		size = expressionInterpreter.getMath(s);	
	}
	public void setSize2(String s) {
		size2 = expressionInterpreter.getMath(s);
	}

	
	@Override
	public void applyCommand() {
		if ((array || table) && (size!=null)) sizeNumber = size.getTreeValue();
		if (table && (size2!=null)) sizeNumber2 = size2.getTreeValue();
		
		
		if (table) {
			variableManager.addTable(name, posun, sizeNumber, posun2, sizeNumber2, type, vizualize);
			if (vizualize) addVisual(variableManager.getTableVariableByName(name));
		} else if (array) {
			variableManager.addArray(name, posun, sizeNumber, type, vizualize);
			if (vizualize) addVisual(variableManager.getArrayVariableByName(name)); 
		} else { variableManager.addVariable(name, type, null, vizualize);
			if (vizualize) addVisual(variableManager.getVariableByName(name));						
		}		
		
	}
	
	public void addVisual(SimpleVariable variable) { visualPanel.addVisualComponent(variable, null, null, params); }
	public void addVisual(TableVariable variable) { visualPanel.addVisualComponent(null, null, variable, params); }
	public void addVisual(ArrayVariable array) { visualPanel.addVisualComponent(null, array, null, params); }
	

	

}
