import { getEnvironmentData as f } from "@b2x/shared/utilities.mjs";
import { subscribeIam as d } from "@b2x/authentication";
import { storage as s } from "@b2x/std/core/storage.mjs";
import { isDebuggerEnable as w, isDebuggerGrouped as h } from "@b2x/std/core/debug.mjs";
import { isLocalhost as L } from "@b2x/std/core/utilities.mjs";
import { consola as g } from "@b2x/std/logger/consola.mjs";
import { BrowserReporter as b } from "@b2x/std/logger/reporters/browser.mjs";
const p = "2.109.14", u = "18.12.2025, 15:05:21", e = "B2X@LAL";
function A() {
  return g.setLogger(e, {
    reporters: [
      new b({
        title: `LAL@${p}-${u}`,
        namespace: e,
        delay: 1500,
        grouped: h(e),
        enabled: w(e) || L()
      })
    ]
  }), {
    createLogger: (o) => g.createLoggerGroup(e, o)
  };
}
const a = A(), y = a.createLogger("HELPERS");
function E(o, t) {
  return {
    authState: {
      jwe: o.jwe,
      email: o.email || ""
    },
    currentPage: window.location.href,
    country: t
  };
}
const $ = () => {
  const o = document.querySelector('script[type="importmap"]');
  if (o?.textContent)
    try {
      return JSON.parse(o.textContent);
    } catch {
      y.error("Error parsing import map");
    }
  return {
    imports: {}
  };
};
async function F() {
  return await new Promise((o) => {
    d((t) => {
      o(t);
    });
  });
}
function l(o, t) {
  const n = new CustomEvent(o, {
    bubbles: !0,
    detail: t
  });
  document.dispatchEvent(n);
}
function M(o) {
  o.isLoggedIn ? s.session.set("ow_aem_loginstate", "logged_in", !1) : s.session.set("ow_aem_loginstate", "logged_out", !1);
}
const c = a.createLogger("FLOW-RUNNER");
class C {
  actionName;
  importPrefix = "@b2x/loginaction/";
  importMap;
  loginData;
  importMapActionUrl;
  constructor(t, n, i) {
    this.actionName = t, this.importMap = i, this.loginData = n, this.importMapActionUrl = this.importMap?.imports[`${this.importPrefix}${this.actionName}`];
  }
  async runCondition() {
    const t = this.importMapActionUrl.split("/");
    t[t.length - 1] = "condition.js";
    const i = await (await import(t.join("/"))).default(this.loginData);
    return c.info(`Checking condition for action: ${this.actionName}`, i ? "🚧" : "❌"), i;
  }
  async runAction() {
    await (await import(
      /* @vite-ignore */
      this.importMapActionUrl
    )).default(this.loginData), c.info(` ✅ Executed action: ${this.actionName}`);
  }
  async run() {
    c.info(`🚀 Running action: ${this.actionName}`);
    try {
      await this.runCondition() && await this.runAction();
    } catch (t) {
      c.warn(`⛔️ Error running condition or action: ${this.actionName}`, t);
    }
  }
}
async function N(o, t) {
  const n = $();
  for (const i of o)
    n.imports[`@b2x/loginaction/${i}`] && await new C(i, t, n).run();
}
const S = a.createLogger("FLOW"), O = ["declarationOfConsent", "checkForConsentUpdates"], r = ["checkForConsentUpdates"], m = {
  hk: r,
  jp: r,
  kr: r,
  la: r,
  mo: r,
  my: r,
  sg: r,
  standard: O
};
function U(o) {
  const t = s.local.get("b2x.lal_flow");
  return t ? (S.warn("Using custom flow", t), t) : m[o] || m.standard;
}
const k = a.createLogger("BOOTSTRAP");
async function R(o, t) {
  try {
    const n = U(o.toLowerCase()), i = E(t, o);
    await N(n, i), l("login-action:done", { country: o });
  } catch (n) {
    l("login-action:failed", { country: o }), k.error("Error initializing login actions library", n);
  }
}
const x = a.createLogger("BOOTSTRAP");
async function D() {
  x.info(`Login Actions library ${p} - ${u}`);
  const { country: o } = (await f("login-actions")).pageEnvironmentVariables, t = await F();
  M(t), t.isLoggedIn && R(o, t);
}
D();
//# sourceMappingURL=bootstrap.mjs.map
