class IngamePanelCustomPanel extends UIElement {
  constructor() {
    super(...arguments);
  }

  connectedCallback() {
    super.connectedCallback();
    fetch(`http://localhost:42888/config`)
      .then((response) => response.json())
      .then((data) => {
        fsltlControls.setAttribute("class", "");
        fsltlActive.setAttribute("class", "panelHidden");
        ifrSlider.setAttribute("value", parseInt(data["ifraircraftlimit"]));
        vfrSlider.setAttribute("value", parseInt(data["vfraircraftlimit"]));
        staticSlider.setAttribute(
          "value",
          parseInt(data["staticaircraftlimit"])
        );
        staticGASlider.setAttribute(
          "value",
          parseInt(data["staticaircraftgalimit"])
        );
        removeSlider.setAttribute("value", parseInt(data["secstilremove"]));
        radiusSlider.setAttribute("value", parseInt(data["spawnRadiusAir"]));
        radiusSliderGround.setAttribute(
          "value",
          parseInt(data["spawnRadiusGround"])
        );
      })
      .catch((error) => {
        fsltlControls.setAttribute("class", "panelHidden");
        fsltlActive.setAttribute("class", "");
        console.log(error.message);
      });

    resetTraffic.addEventListener("click", () => {
      fetch("http://localhost:42888/reset").catch((error) =>
        console.log(error.message)
      );
    });
    cullClose.addEventListener("click", () => {
      fetch("http://localhost:42888/nearcull").catch((error) =>
        console.log(error.message)
      );
    });
    radiusSlider.addEventListener("change", (event) => {
      fetch(`http://localhost:42888/set/radiusair/${event.target.value}`).catch(
        (error) => console.log(error.message)
      );
    });
    radiusSliderGround.addEventListener("change", (event) => {
      fetch(
        `http://localhost:42888/set/radiusground/${event.target.value}`
      ).catch((error) => console.log(error.message));
    });
    ifrSlider.addEventListener("change", (event) => {
      fetch(`http://localhost:42888/set/ifr/${event.target.value}`).catch(
        (error) => console.log(error.message)
      );
    });
    vfrSlider.addEventListener("change", (event) => {
      fetch(`http://localhost:42888/set/vfr/${event.target.value}`).catch(
        (error) => console.log(error.message)
      );
    });
    removeSlider.addEventListener("change", (event) => {
      fetch(`http://localhost:42888/set/time/${event.target.value}`).catch(
        (error) => console.log(error.message)
      );
    });
    staticSlider.addEventListener("change", (event) => {
      fetch(`http://localhost:42888/set/static/${event.target.value}`).catch(
        (error) => console.log(error.message)
      );
    });
    staticGASlider.addEventListener("change", (event) => {
      fetch(`http://localhost:42888/set/staticga/${event.target.value}`).catch(
        (error) => console.log(error.message)
      );
    });
  }
  initialize() {}
  disconnectedCallback() {
    super.disconnectedCallback();
  }
  updateImage() {}
}

window.customElements.define("ingamepanel-custom", IngamePanelCustomPanel);
checkAutoload();
