<!DOCTYPE html>
<html lang="de">
<head>
	<title>Config NCT Tray Notifier</title>
	<meta charset="UTF-8">
	<!-- meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-inline'" -->
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="fonts/Linearicons-Free-v1.0.0/icon-font.min.css">
	<link rel="stylesheet" type="text/css" href="css/main.css">
	<style>
		.invis {
			display: none;
		}
		fieldset { 
			border: none;
			padding: 0;
		}
		ul { 
			padding-inline-start: 0px;
			margin: 0px;
		}
		li { list-style-type: none; }
	</style>
	<script>
		const electron = require('electron');
		const {ipcRenderer} = electron;
		function changeVal(i,v){
//			console.log(i + ' : ' + v);
			const {ipcRenderer} = require('electron');
			let newcontent = btoa(document.getElementById('ncurl').value);
			ipcRenderer.send('serverChange', newcontent );
			console.log("serverChange: " + newcontent);
		}
		function changeOpt(i,v,c){
			//console.log(i + ' : ' + v + ' : ' + c);
			const {ipcRenderer} = require('electron');
			//let newcontent = i+'_'+v+':'+c;
			let newcontent = "";
			var x = document.getElementsByName("option");
			var i;
			console.log(x.length);
			for (i = 0; i < x.length; i++) {
				if (x[i].type == "checkbox") {
					console.log(i);
					newcontent = newcontent + x[i].value + ':' + x[i].checked + "\n";
				}
			} 
			ipcRenderer.send('optionChange', newcontent );
		}
		function connectServer() {
			const {ipcRenderer} = require('electron');
			ipcRenderer.send('connectServer', '' );
			console.log("sent IPC");
			myWinRef = window.self;
			//alert(document.getElementById('ncurl').value);
			myWinRef.close();
		}
	</script>
</head>
<body>
<div class="container-contact100">
<div class="wrap-contact100">
	<form id="configList">
	
	<div class="wrap-input100 validate-input" data-validate="URL is required">
		<input  class="input100" type="text" size="30" id="ncurl" onchange="changeVal(this.id,this.value);" placeholder="URL">
		<label class="label-input100" for="ncurl">
			<span class="lnr lnr-cloud-sync"></span>
		</label>
	</div>
	<input class="contact100-form-btn" type="submit" id="connect" onclick="connectServer();" value="Connect..."></input><br><br>

  
  <fieldset>
    <ul>
      <li class="in-vis contact100-form-checkbox"> 
				<input class="input-checkbox100" id="ckb1" type="checkbox" name="option" value="browser" onchange="changeOpt(this.name,this.value,this.checked);" >
				<label class="label-checkbox100" for="ckb1">
				use external default browser instead of built-in chromium
        </label>
      </li>
      <li class="in-vis contact100-form-checkbox"> 
        <input class="input-checkbox100" id="ckb2" type="checkbox" name="option" value="base-url" onchange="changeOpt(this.name,this.value,this.checked);">
        <label class="label-checkbox100" for="ckb2">
          default to NC-Talk instead of base URL
        </label>
      </li>
      <li class="in-vis contact100-form-checkbox">  
        <input class="input-checkbox100" id="ckb3" type="checkbox" name="option" value="nontalk" onchange="changeOpt(this.name,this.value,this.checked);">
        <label class="label-checkbox100" for="ckb3">
          limit notifications to Nextcloud Talk only
        </label>
      </li>
      <li class="in-vis contact100-form-checkbox">  
        <input class="input-checkbox100" id="ckb4" type="checkbox" name="option" value="debug" onchange="changeOpt(this.name,this.value,this.checked);">
        <label class="label-checkbox100" for="ckb4">
          activate debug mode
        </label>
      </li>
    </ul> 
  </fieldset> 
	</form>
</div>	
</div>
<script src="form.js"></script>
<script>

		console.log("Neu laden!");
		let arg = ipcRenderer.sendSync('initServerUrl', 'connection' );
		console.log(arg);
		CV = arg.split(':');
		document.getElementById('ncurl').value = atob(CV[0]);
		// set options
		var x = document.getElementsByName("option");
		var i;
		for (i = 0; i < x.length; i++) {
			if (x[i].value == 'debug' && CV[1] == 'true') { x[i].checked = true ; }
			if (x[i].value == 'browser' && CV[2] == 'true') { x[i].checked = true ; }
			if (x[i].value == 'base-url' && CV[3] == 'true') { x[i].checked = true ; }
			if (x[i].value == 'nontalk' && CV[4] == 'true') { x[i].checked = true ; }
		} 

		//document.getElementById('ncuser').value = atob(CV[1]);
		//document.getElementById('ncpwd').value = atob(CV[2]);

</script>
</body>
</html>