/* clang-format off */

//static const char html_confadd_script[] PROGMEM = R"=====(
//<script>
//  function g(i) { return document.getElementById(i) };
//  function sp(i){g(i).type=(g(i).type==='text'?'password':'text');}
//  var xhttp, reqTime, reqFin;
//  function setCbx(el, da) {
//    if(el !== null) {
//      if(da == '1') {
//        el.checked = true;
//        el.style.visibility = 'visible';
//      }
//      else {
//        el.checked = false;
//        el.style.visibility = 'visible';
//      }
//    }
//  }
//  function updCbxVal(el) {
//    if(el !== null) {
//      if (el.checked) el.value = '1';
//      else {
//        el.checked = true;
//      el.value = '0';
//        el.style.visibility = 'hidden';
//      }
//    }
//  }

static const char html_confadd_script[] PROGMEM = R"=====(
  function transmit(f) {
    if (!xhttp) {   
    reqTime = 0;
    reqFin = false;
    xhttp = new XMLHttpRequest();
    xhttp.timeout = 1000;
    xhttp.overrideMimeType('application/json');
    xhttp.open('POST', 'confDataAdd');
    xhttp.send(f ? (new FormData(f)) : '');
    xhttp.onreadystatechange = function () {
      if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
        var data = JSON.parse(xhttp.responseText);
        g('PIRTop').value = data.PIRTop;
        g('PIROnPld').value = data.PIROnPld;
        g('PIROffPld').value = data.PIROffPld;
        g('outTempTop').value = data.outTempTop;
        g('outHumTop').value = data.outHumTop;
        xhttp = null;
        reqFin = true;
       }
       else {
         if(!reqFin && reqTime > 10) {
           xhttp = null;
           reqFin = true;
         }
       }
     }
   }
    return false;
  }
  //transmit();
  function saveConf() {
    g('frmConf').submit();
  }
  function init() {
    transmit();
  }
)====="; // html_confadd_script
//  setInterval(function () { ++reqTime; }, 1000);
//</script>
//)====="; // html_confadd_script

static const char html_confadd_body[] PROGMEM = R"=====(
<b>Configuration - Additional Functions</b>
<div class='config'>
<form id='frmConf' action='setConfAdd' method='POST'>
<br>
<fieldset>
<legend>PIR Sensor</legend>
<p><b>MQTT Publish Topic</b><br><input type='text' name='PIRTop' id='PIRTop'/></p>
<p><b>MQTT ON Payload</b><br><input type='text' name='PIROnPld' id='PIROnPld'/></p>
<p><b>MQTT OFF Payload</b><br><input type='text' name='PIROffPld' id='PIROffPld'/></p>
</fieldset>
<div></div><br>
<fieldset>
<legend>Outside Temp/Hum via MQTT</legend>
<p class='n'>Only used if not empty, can be subscribed to and valid data is sent. </p>
<p><b>O-Temp In-Topic</b><br><input type='text' name='outTempTop' id='outTempTop'/></p>
<p><b>O-Hum In-Topic</b><br><input type='text' name='outHumTop' id='outHumTop'/><br>
</fieldset>

<br>
</form>
<div></div>
<table style='width:100%'>
<td style='width:50%'><button onclick='location="conf";' class='bgrey'>Cancel</button></td>
<td style='width:50%'><button onclick='return saveConf()' class='bred'>Save</button></td>
</tr></table>
</div>
)====="; // html_confadd_body
