/**
 * @file app.js
 * @author Andreas Tholen
 * Contact: info@littwin-systechnik.de
 * @version 0.5.3
 * @description Basic Functions
*/

$(document).foundation();

document.getElementById("fullSideMenuCard").style.height = windowHeight+"px";

// Sidemenu Config
if ((!standardSideMenu) || (fullSideMenu)) {
  const collection = document.getElementsByClassName("standardSideMenu");
  for (let i = 0; i < collection.length; i++) {
  collection[i].style.display = "none";
  }
}

if ((!fullSideMenu) || (standardSideMenu)) { 
  const collectionb = document.getElementsByClassName("fullSideMenu");
  for (let i = 0; i < collectionb.length; i++) {
  collectionb[i].style.display = "none";
  }
}

var stationCardTempList = "";
var stationCardTemp = '<div class="card">'
						+'<div class="title-bar">'
            +'<div class="title-bar-left">'
            +'<span class="title-bar-title" style="color:#000000;padding-left:0.5rem ;">Standort</span>'
            +'</div>'
            +'<div class="title-bar-right">'
            +'<a><i class="fi-alert" title="Weitere Infos" style="color:red;font-size:1.5rem;padding-right:10px;" data-open="weitereInfos"></i></a>'
            +'</div>'
						+'</div>'
						+'<div class="card-section" style="padding: 0px 0px 1rem 1rem !important">'
            +'Test'
						+'</div>'
            +'</div>';

for (let index = 0; index < 11; index++) {
  stationCardTempList += stationCardTemp; 
}

document.getElementById('stationenFullSideMenu').innerHTML = stationCardTempList;

function getDataMenu() {
  var stationsListing = [];

  // Stationen erfassen
  for (var i = 0; i < dataStaticlength; i++) {	
    var gisStatics = dataStatic[i];
    var stationListing = gisStatics.Area_Name; // Area_Name
        stationsListing.push(stationListing);
  }

  // Doppelte Einträge löschen
  console.log("%cMAP| Einträge der Stationen werden geprüft",'color: green');
  let uniqueStations = [];
  stationsListing.forEach((c) => {
      if (!uniqueStations.includes(c)) {
        uniqueStations.push(c);
      }
  });

  console.log("%cMAP| Stationen indexiert: %c"+uniqueStations.sort(),'color: green', 'color:grey');
  uniqueStations = uniqueStations.sort();

  var select = document.getElementById("stationListing");
  
  for(var i = 0; i < uniqueStations.length; i++) {
      var opt = uniqueStations[i];
      var el = document.createElement("option");
      el.textContent = opt;
      el.value = opt;
      el.style.color = "#000000";
      el.style.fontWeight = "thin";
      select.appendChild(el);
  }
}

var checkbox = document.querySelector("#box-TALAS");

checkbox.addEventListener('change', function() {
  if (this.checked) {
    map.addLayer(TALAS);
    
    console.log("TALAS is checked..");
  } else {
    map.removeLayer(TALAS);
   
    console.log("TALAS is not checked..");
  }
});

var checkbox = document.querySelector("#box-GMA");

checkbox.addEventListener('change', function() {
  if (this.checked) {
    map.addLayer(GMA);
    document.getElementById("data-"+LocID).style.display = "none";
    console.log("GMA is checked..");
  } else {
    map.removeLayer(GMA);
    
    console.log("GMA is not checked..");
  }
});

var checkbox = document.querySelector("#box-MODEM");

checkbox.addEventListener('change', function() {
  if (this.checked) {
    map.addLayer(GSM);
    
    console.log("GSM is checked..");
  } else {
    map.removeLayer(GSM);
    
    console.log("GSM is not checked..");
  }
});

var checkbox = document.querySelector("#box-SIEMENS");

checkbox.addEventListener('change', function() {
  if (this.checked) {
    map.addLayer(Siemens);
    
    console.log("Notrufsäulen is checked..");
  } else {
    map.removeLayer(Siemens);
    
    console.log("Notrufsäulen is not checked..");
  }
});


// ISS Positions-Update Test
var iss;
function update_position() {
    $.getJSON('http://api.open-notify.org/iss-now.json', function(data) {
        var latitude = data["iss_position"]["latitude"];
        var longitude = data["iss_position"]["longitude"];
        if (!iss) {
            iss = L.marker([latitude,longitude], {icon: spaceStationMarker}).bindPopup("Ich bin die ISS").addTo(map);
        }
        iss.setLatLng([latitude,longitude]).update();
        setTimeout(update_position, 1000);
    });
}
update_position();




