package jkind.xtext.ui.views;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import jkind.results.layout.Layout;
import jkind.xtext.jkind.File;
import jkind.xtext.jkind.Node;
import jkind.xtext.jkind.Variable;
import jkind.xtext.util.Util;

public class JKindNodeLayout implements Layout {
	private final List<String> nodeInputs;
	private final List<String> nodeOutputs;
	private final List<String> nodeLocals;
	
	private static final String INPUTS = "Inputs";
	private static final String OUTPUTS = "Outputs";
	private static final String LOCALS = "Locals";
	private static final String INLINED = "Inlined";
	private static final String[] CATEGORIES = { INPUTS, OUTPUTS, LOCALS, INLINED };

	public JKindNodeLayout(Node node) {
		if (node == null) {
			throw new IllegalArgumentException("Unable to create layout for null node");
		}
		
		this.nodeInputs = getNames(Util.getVariables(node.getInputs()));
		this.nodeOutputs = getNames(Util.getVariables(node.getOutputs()));
		this.nodeLocals = getNames(Util.getVariables(node.getLocals()));
	}
	
	public JKindNodeLayout(File file) {
		this(Util.getMainNode(file));
	}
	
	private List<String> getNames(List<Variable> variables) {
		List<String> names = new ArrayList<>();
		for (Variable v : variables) {
			names.add(v.getName());
		}
		return names;
	}

	@Override
	public List<String> getCategories() {
		return Arrays.asList(CATEGORIES);
	}

	@Override
	public String getCategory(String signal) {
		if (nodeInputs.contains(signal)) {
			return INPUTS;
		} else if (nodeOutputs.contains(signal)) {
			return OUTPUTS;
		} else if (nodeLocals.contains(signal)) {
			return LOCALS;
		} else {
			return INLINED;
		}
	}

}
@@ -1522,24 +1522,71 @@
  signal) %7B%0D%0A
+%09%09String prefix = signal.split(%22%5C%5C.%7C%5C%5C%5B%22)%5B0%5D;%0D%0A
 %09%09if (nodeIn
@@ -1591,38 +1591,38 @@
 Inputs.contains(
-signal
+prefix
 )) %7B%0D%0A%09%09%09return 
@@ -1656,38 +1656,38 @@
 utputs.contains(
-signal
+prefix
 )) %7B%0D%0A%09%09%09return 
@@ -1729,22 +1729,22 @@
 ontains(
-signal
+prefix
 )) %7B%0D%0A%09%09

Handle complex types in node layout