package language.visual;

import language.CodeLanguage;
import language.VizLanguage;
import background.CommandManager;
import background.commands.*;

public abstract class SimpleVizLanguage extends VizLanguage {

	public SimpleVizLanguage(CommandManager cm, CodeLanguage cl) { super(cm, cl); }
	
	@Override
	public void recognizeData(String s, Command c) {		
		Boolean isUniversal = true;		
		switch (c.getType()) {				// spolocne prikazy			
			case "Variable": {	/* Format: vizVar /cX:suradnica cY:suradnica dizajn:typ  /int meno; */				 				
				s = s.replaceFirst(getReverse("premenna"), "");
								
				if (s.contains("#")) {	
					s = processParam(s, c);					
				} 				
				
				s = codeLang.getReverse("premenna").trim() + " "+ s;
				s = s.trim();
								
				break;
			}	
			case "Operation": {	/* Format: vizOperation meno=meno+meno2; */			
				s = s.replaceFirst(getReverse("operacia"), "");
				break;
			}
			case "If": {	/* Format: vizIf (podmienka==true) */			
				s = s.replaceFirst(getReverse("if"), codeLang.getReverse("if"));
				break;
			}
			case "While": {	/* Format: vizWhile (podmienka==true) */			
				s = s.replaceFirst(getReverse("while"), codeLang.getReverse("while"));
				break;
			}
			case "Repeat": {	/* Format: vizRepeat until (podmienka==true) */			
				s = s.replaceFirst(getReverse("repeat"), codeLang.getReverse("repeat"));
				break;
			}
			case "For": {	/* Format: VizFor (i=1; i<=5; i=i+1) */			
				s = s.replaceFirst(getReverse("for"), codeLang.getReverse("for"));
				break;
			}
			case "Read": {
				s = s.replaceFirst(getReverse("vstup"), "");
				break;
			}
			case "Write": {
				s = s.replaceFirst(getReverse("vystup"), "");
				break;
			}

			default: {isUniversal = false; break;}
		}
				
		if (isUniversal) codeLang.recognizeData(s.trim(), c);
		else {
			switch (c.getType()) {
				case "Pause": {
					break;
				}
				case "Image": {				// vizImage /file:pripona/;
					s = s.replaceFirst(getReverse("image"), "").trim();
					if (s.contains("#")) {	
						processParam(s, c);					
					} 				
					break;
				}
				case "Global": {				// vizGlobal /design:simple atd/;
					s = s.replaceFirst(getReverse("nastavenia"), "").trim();
					if (s.contains("#")) {	
						processParam(s, c);					
					} 				
					break;
				}
				case "Question": {			// vizQuestion "question" "correctAnswer"; OR vizQuestion "question" variableName;
					Question c2 = (Question) c;
					String parts[] = s.split("\"");
					
					c2.question = parts[1];
					if (parts.length>=4) {						
						c2.answer = parts[3];
					} else {	
						c2.variable = parts[2].trim();						
					}
					
					break;
				}
			}
		}
		
		c.vizualize = true;
	}	
	
}
