(() => {
  "use strict";

  try {
    const theme = localStorage.getItem("iseca-boot-theme-v1");
    if (theme === "dark" || theme === "light") document.documentElement.dataset.theme = theme;
  } catch {
  }

  document.addEventListener("DOMContentLoaded", () => {
    setTimeout(() => {
      const overlay = document.getElementById("appBusyOverlay");
      if (overlay && overlay.dataset.hidden !== "true") overlay.dataset.hidden = "true";
    }, 45_000);

    fetch("pliki/wersja-aplikacji.json", { cache: "no-store" })
      .then((response) => (response.ok ? response.json() : null))
      .then((data) => {
        const footer = document.getElementById("appFooterVersion");
        const gateVersion = document.getElementById("accountGateVersion");
        if (data && typeof data.version === "string" && /^\d+\.\d+\.\d+$/.test(data.version)) {
          if (footer) footer.textContent = `Wersja ${data.version}`;
          if (gateVersion) gateVersion.textContent = `Wersja ${data.version}`;
        }
      })
      .catch(() => {});
  }, { once: true });
})();
