#include <Arduino.h>
#include "nodemcu.h"

Nodemcu::Nodemcu() {

}

String Nodemcu::orientation() {
		
String s = "<center><div id=\"alpha\"></div><div id=\"beta\"></div><div id=\"gamma\"></div></center>\n";
s += "<script>\n if(window.DeviceOrientationEvent)\n {\n  window.addEventListener(\"deviceorientation\", process, false);\n }\n function process(event) {\n var alpha = parseInt(event.alpha);\n var beta = parseInt(event.beta);\n var gamma = parseInt(event.gamma);\n document.getElementById(\"alpha\").innerHTML = \"Alpha : \" + alpha;\n document.getElementById(\"beta\").innerHTML = \"Beta : \" + beta;\n document.getElementById(\"gamma\").innerHTML = \"Gamma : \" + gamma;\n var xhttp = new XMLHttpRequest();\n xhttp.open(\"GET\", \"angle?alpha=\"+alpha+\"&beta=\"+beta+\"&gamma=\"+gamma, false);\n xhttp.send();\n }\n </script>\n";

return s;
}

String Nodemcu::curseurweb(String nomcurseur, int mini, int maxi) {

  String s = "<br><br><center><span>"+nomcurseur+"</span>";
  nomcurseur.replace(" ", "");
  s += "<span id=\""+nomcurseur+"\"></span><div class=\"curseurcontainer\"><input type=\"range\" class=\"curseur\" value=\"0\" min=\""+mini+"\" max=\""+maxi+"\" oninput=\"sendData('"+nomcurseur+"', this.value)\"></div></center>"; 

return s;
}

String Nodemcu::boite(String nomboite) {

  String s = "<br><br><center><span>"+nomboite+"</span>";
  nomboite.replace(" ", "");
  s += "<div class=\"curseurcontainer\"><input type=\"text\" value=\"\"  onchange=\"sendData('"+nomboite+"', this.value)\"></div></center>"; 

return s;
}


String Nodemcu::poussoircentre(String nompoussoir, String couleur) {
	
	String _nompoussoir = nompoussoir;
	nompoussoir.replace(" ", "");

	String s = "<button style=\"position:sticky;left:38%;font-size:400%;color:white;text-align:center;background-color:"+couleur+";width:25%;margin:2%;padding-top:5%;padding-bottom:5%;border-radius:10%\" ontouchstart=\"sendEvent('"+nompoussoir+"','1')\" ontouchend=\"sendEvent('"+nompoussoir+"','0')\" oncontextmenu=\"return false\" onselectstart=\"return false\">"+_nompoussoir+"</button>";

return s;	
}	


String Nodemcu::poussoir(String nompoussoir, String place, String couleur) {

	String _nompoussoir = nompoussoir;
	nompoussoir.replace(" ", "");
	
	String s = "<button style=\"float:"+place+";font-size:400%;color:white;text-align:center;background-color:"+couleur+";width:25%;margin:2%;padding-top:5%;padding-bottom:5%;border-radius:10%\" ontouchstart=\"sendEvent('"+nompoussoir+"','1')\" ontouchend=\"sendEvent('"+nompoussoir+"','0')\" oncontextmenu=\"return false\" onselectstart=\"return false\">"+_nompoussoir+"</button>";

return s;	
}	

String Nodemcu::boutonweb(String nombouton) {

  String s = "<br><br><center><div>"+nombouton+"</div>";
  nombouton.replace(" ", "");
  s += "<label class=\"switch\"><input type=\"checkbox\" id=\""+nombouton+"\" onclick =\"sendCheck('"+nombouton+"')\"><span class=\"slider round\"></span></label></center>"; 

return s;
}


String Nodemcu::interval(String adc, String unit, int periode) {
	
String s = "<br><br><center><span>"+adc+" : </span>";	
adc.replace(" ", "");
adc.replace("\'", "");
s += "<span id=\""+adc+"\"></span><span> "+unit+"</span></center>\n";
s += "<script>\nsetInterval(function() {\n"+adc+"();\n}, "+periode+");\nfunction "+adc+"() {\nvar xhttp = new XMLHttpRequest();\n xhttp.onreadystatechange = function() {\nif (this.readyState == 4 && this.status == 200) {\ndocument.getElementById(\""+adc+"\").innerHTML =this.responseText;\n}\n};\nxhttp.open(\"GET\", \""+adc+"\", true);\nxhttp.send();\n}\n</script>\n";

return s;
}

String Nodemcu::telecommande() {
String s = "<div style=\"position:relative;width:90%;margin:auto;text-align:center\">";
s += "<button style=\"background-color:blue;width:25%;padding-top:25%;margin:2%;border-radius:20%\" ontouchstart=\"sendEvent('bleu','1')\" ontouchend=\"sendEvent('bleu','0')\"></button><br>";
s += "<button style=\"background-color:red;float:left;width:25%;padding-top:25%;margin:2%;border-radius:20%\" ontouchstart=\"sendEvent('rouge','1')\" ontouchend=\"sendEvent('rouge','0')\"></button>";
s += "<button style=\"background-color:black;width:25%;padding-top:25%;margin:2%;border-radius:20%\" ontouchstart=\"sendEvent('noir','1')\" ontouchend=\"sendEvent('noir','0')\"></button>";
s += "<button style=\"background-color:green;float:right;width:25%;padding-top:25%;margin:2%;border-radius:20%\" ontouchstart=\"sendEvent('vert','1')\" ontouchend=\"sendEvent('vert','0')\"></button>";
s += "<button style=\"background-color:yellow;width:25%;padding-top:25%;margin:2%;border-radius:20%\" ontouchstart=\"sendEvent('jaune','1')\" ontouchend=\"sendEvent('jaune','0')\"></button><br>";
s += "</div>";

	
return s;	
}