package org.arachb.api.provider;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class DefaultPage extends AbstractPage {

	enum Field implements PageField{
		LOCALID("localIdentifier","local identifier","");
		
		private final String key;
		private final String displayStr;
		private final String separator;
		static final Map<String,Field> keylookup = new HashMap<>();
		
		Field(String k,String ds,String s){
			this.key = k;
			this.displayStr = ds;
			this.separator = s;
		}
		
		@Override
		public String displayString(){
			return displayStr;
		}
		
		@Override
		public String formatValue(String fieldValue){
			if ("".equals(separator)){
				return fieldValue;
			}
			else {
				return fieldValue;
			}
		}

		@Override
		public String keyString() {
			return key;
		}

		@Override
		public PageField lookupKey(String key) {
			return Field.keylookup.get(key);
		}
	}

	
	public DefaultPage(MetaDataSummary mds){
		super(mds);
	}

	@Override
	public String generateHTML() throws IOException{
		String result = "";
		result += "<!DOCTYPE html>";
		result += "<html lang=\"en\">";
		result += "<head>";
		result += generateHeader("publication");
		result += "</head>";
		result += "<body>";

		result += addNavBar();
		result += "   <div class=\"container\">";
		if (metadata.contains("title")){
			result += String.format("      <h3>%s</h3>",metadata.get("title"));
		}
		else {
			result += String.format("      <h3>%s</h3>",metadata.get("localIdentifier"));			
		}
		result += "   </div>";
		result += "   <div class=\"row\">";
		result += "      <div class=\"span11\">";
		result += "         <div id=\"results\">";
		result += metadata.generateResults(Field.values());
		result += "		    </div>";
		result += "      </div>";
		result += "   </div>";
		result += "   <hr/>";
		result += addFooter();
		result += addScript(JQUERYSTRING);
		result += addScript(BOOTSTRAPSTRING);
		result += addScript(ENVSTRING);
		result += "</body>";
		result += "</html>";
		return result;
	}




}

@@ -1174,18 +1174,14 @@
 er(%22
-publicatio
+unknow
 n%22);
@@ -1602,12 +1602,15 @@
 s=%5C%22
-span
+col-md-
 11%5C%22

update for bootstrap 3.3; some refactoring