const simController = new SimController();

const loadSplash = () => {
  simController.loadSplash();
};

const loadSim = (key) => {
  simController.loadSim(key);
};

const loadTask = (title) => {
  simController.loadTask(title);
};

const startSim = () => {
  $("#topDataMenu").attr("style", "display: block;");
  simController.loadFirstSim();
  simController.start();
};

const resumeSim = () => {
  simController.start();
};

const pauseSim = () => {
  simController.pause();
};

const setSimulationTime = (event) => {
  const dateWithoutLocalOffset = new Date(
    event.getTime() - event.getTimezoneOffset() * 60 * 1000
  );

  simController.setSimulationTime(
    luxon.DateTime.fromISO(dateWithoutLocalOffset.toISOString())
  );
  $("#timeControl").toggleClass("active");
};

// $(document).ready equivalent
jQuery(() => {
  simController.init();

  window.loadSim = loadSim;
  window.loadTask = loadTask;
  window.loadSplash = loadSplash;

  window.startSim = startSim;
  window.pauseSim = pauseSim;
  window.resumeSim = resumeSim;

  window.setSimulationTime = setSimulationTime;

  $("#setSimDateTimeCalendar").datetimepicker({
    value: simController.getCurrentTime().toUTC().toISO(),
    onChangeDateTime: setSimulationTime,
    inline: true,
    minDateTime: simController.getStartTime().toUTC().toISO(),
    maxDateTime: simController.getEndTime().plus({ hours: 1 }).toUTC().toISO(),
  });

  $("#timeControlToggle").on("click", function () {
    $("#timeControl").toggleClass("active");
  });
});
