/* clang-format off */


//<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 selectElement(el, val) {    
//    el.value = val;
//  }
//  function setCbx(el, da) {
//    if(da == '1') {
//      el.checked = true;
//      el.style.visibility = 'visible';
//    }
//    else {
//      el.checked = false;
//      el.style.visibility = 'visible';
//    }
//  }
//  function updCbxVal(el) {
//    if (el.checked) el.value = '1';
//    else {
//      el.checked = true;
//    el.value = '0';
//      el.style.visibility = 'hidden';
//    }
//  }

static const char html_conflog_script[] PROGMEM = R"=====(
  function transmit(f) {
    if (!xhttp) {   
    reqTime = 0;
    reqFin = false;
    updCbxVal(g('logWebRequests'));
    xhttp = new XMLHttpRequest();
    xhttp.timeout = 1000;
    xhttp.overrideMimeType('application/json');
    xhttp.open('POST', 'confDataLog');
    xhttp.send(f ? (new FormData(f)) : '');
    xhttp.onreadystatechange = function () {
      if (xhttp.readyState === XMLHttpRequest.DONE && xhttp.status === 200) {
        var data = JSON.parse(xhttp.responseText);
		    selectElement(g('logLevSer'), data.logLevSer);
		    selectElement(g('logLevWeb'), data.logLevWeb);
		    selectElement(g('logLevMqtt'), data.logLevMqtt);
        setCbx(g('logWebRequests'), data.logWebRequests);
        xhttp = null;
        reqFin = true;
       }
       else {
         if(!reqFin && reqTime > 10) {
           xhttp = null;
           reqFin = true;
         }
       }
     }
   }
    return false;
  }
  function saveConf() {
    updCbxVal(g('logWebRequests'));
    g('frmConf').submit();
  }
  function init() {
    transmit();
  }
)====="; // html_confweb_script
//  setInterval(function () { ++reqTime; }, 1000);
//</script>


static const char html_conflog_body[] PROGMEM = R"=====(
<p><b>Configuration - Logging</b></p>
<div class='config'>
<form id='frmConf' action='setConfLog' method='POST'>
<fieldset>
<legend>Log Levels</legend>
<p><b>Serial</b><br>
<select name='logLevSer' id='logLevSer'>
  <option value="0">Off</option>
  <option value="1">Error</option>
  <option value="2">Warn</option>
  <option value="3">Info</option>
  <option value="4">Debug</option>
  <option value="5">Verbose</option>
</select></p>
<p><b>Web-Console</b><br>
<select name='logLevWeb' id='logLevWeb'>
  <option value="0">Off</option>
  <option value="1">Error</option>
  <option value="2">Warn</option>
  <option value="3">Info</option>
  <option value="4">Debug</option>
  <option value="5">Verbose</option>
</select></p>
<p><b>MQTT</b><br>
<select name='logLevMqtt' id='logLevMqtt'>
  <option value="0">Off</option>
  <option value="1">Error</option>
  <option value="2">Warn</option>
  <option value="3">Info</option>
  <option value="4">Debug</option>
  <option value="5">Verbose</option>
</select></p>
<br>
<p><b>Log Web Requests</b>&nbsp;<input type='checkbox' name='logWebRequests' id='logWebRequests'></p>
</fieldset>
</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></div>
</div>
)====="; // html_confweb_body
