package language;

import java.util.HashMap;
import java.util.Set;

import language.visual.English;
import language.visual.Slovak;


import background.CommandManager;
import background.commands.Command;

public class VizLanguage extends Language {	
	
	public CodeLanguage codeLang;
	public HashMap<String, String> paramDictionary;	
		
	public VizLanguage(CommandManager cm, CodeLanguage cl) {
		super(cm);
		codeLang = cl;
		paramDictionary = new HashMap<String, String>();
		createParamDictionary();
	}
	
	public static VizLanguage getLangByName(String name, CodeLanguage cl, CommandManager cm) {
		switch (name) {
			case "Slovenčina": return new Slovak(cm, cl);
			case "Angličtina": return new English(cm, cl);
			default: return new English(cm, cl);
		}
	}
	
	public void createParamDictionary() {			
		paramDictionary.put("multiplicator", "multiplicator");
		paramDictionary.put("type", "type");
		paramDictionary.put("file", "type");
		paramDictionary.put("design", "design");
		paramDictionary.put("varVisTech", "varVisTech");
		paramDictionary.put("arrayVisTech", "arrayVisTech");
		paramDictionary.put("duoArrayVisTech", "duoArrayVisTech");
		paramDictionary.put("cX", "x");
		paramDictionary.put("cY", "y");
		paramDictionary.put("color", "color");
	}
	
	public Set<String> getParamWords() {
		return paramDictionary.keySet();	
	}
	
	public String processParam(String s, Command c2) {	
		String parts[] = s.trim().split(" ");
				
		int partNum = 0;
		while ((partNum<parts.length) && parts[partNum].contains("#")) {
			
			String subparts[] = parts[partNum].split("#");
			c2.params.put(translateParam(subparts[0]), subparts[1]);
			partNum++;
		}
							
		s="";
		while (partNum<parts.length) {
			s+=parts[partNum] + " ";
			partNum++;
		}				
		s = s.trim();
		
		return s;
	}

	@Override
	public Command getCommandByName(String name) {
		switch (name) {
			case "premenna": return commandManager.getCommand("Variable", true);
			case "pole": return commandManager.getCommand("Array", true);
			case "for": return commandManager.getCommand("For", true);
			case "repeat": return commandManager.getCommand("Repeat", true);
			case "while": return commandManager.getCommand("While", true);
			case "if": return commandManager.getCommand("If", true);
			case "operacia": return commandManager.getCommand("Operation", true);
			case "pause": return commandManager.getCommand("Breakpoint", true);
			case "vstup": return commandManager.getCommand("Read", true);
			case "vystup": return commandManager.getCommand("Write", true);
			case "image": return commandManager.getCommand("Image", true);
			case "question": return commandManager.getCommand("Question", true);
			case "nastavenia": return commandManager.getCommand("Global", true);
		}
		return null;		
	}
	
	public String translateParam(String s) {
		return paramDictionary.get(s);
	}
	
	
}
