async function accessCheck() {
  var url = ROOT_URL + "/functions/checkaccess.php?tenant=" + TENANT_URL;
  try {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
    });
    const ret = await response.text();
    if (ret.trim() === "s") {
      location.href = "index.php?op=logout&reason=blocked";
    }
    // console.log('pinged');
  } catch (error) {
    console.error("Error:", error);
  }
}

setInterval(function () {
  accessCheck();
}, 30000);

document.addEventListener("DOMContentLoaded", function () {
  initializeDatePickers();
});

function initializeDatePickers() {
  document.querySelectorAll(".date-picker").forEach(function (element) {
    const dateType = element.getAttribute("data-date-type");
    let options = {
      confirmDateOnSelect: true,
      toggleButton: false,
    };

    if (dateType === "future") {
      options.min = new Date();
    } else if (dateType === "past") {
      options.max = new Date();
    }

    new mdb.Datepicker(element, options);
  });
}
