var h = Object.defineProperty;
var w = (o, t, n) => t in o ? h(o, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[t] = n;
var e = (o, t, n) => w(o, typeof t != "symbol" ? t + "" : t, n);
import { getAemNamespace as L } from "@b2x/std/helpers/environment.mjs";
import { subscribeIam as b } from "@b2x/authentication";
import { storage as l } from "@b2x/std/core/storage.mjs";
import { isDebuggerGrouped as A, isDebuggerEnable as y } from "@b2x/std/core/debug.mjs";
import { isLocalhost as E } from "@b2x/std/core/utilities.mjs";
import { consola as m } from "@b2x/std/logger/consola.mjs";
import { BrowserReporter as $ } from "@b2x/std/logger/reporters/browser.mjs";
/**
 * @preserve
 * Licenses of bundled dependencies can be found in dependencies-licenses.txt
 */
const f = "2.105.0", d = "8.7.2025, 12:52:00", a = "B2X@LAL";
function F() {
  return m.setLogger(a, {
    reporters: [
      new $({
        title: `LAL@${f}-${d}`,
        namespace: a,
        delay: 1500,
        grouped: A(a),
        enabled: y(a) || E()
      })
    ]
  }), {
    createLogger: (o) => m.createLoggerGroup(a, o)
  };
}
const c = F(), N = c.createLogger("HELPERS");
function C(o, t) {
  return {
    authState: {
      jwe: o.jwe,
      email: o.email || ""
    },
    currentPage: window.location.href,
    country: t
  };
}
const M = () => {
  const o = document.querySelector('script[type="importmap"]');
  if (o != null && o.textContent)
    try {
      return JSON.parse(o.textContent);
    } catch {
      N.error("Error parsing import map");
    }
  return {
    imports: {}
  };
};
async function S() {
  return await new Promise((o) => {
    b((t) => {
      o(t);
    });
  });
}
function p(o, t) {
  const n = new CustomEvent(o, {
    bubbles: !0,
    detail: t
  });
  document.dispatchEvent(n);
}
function k(o) {
  o.isLoggedIn ? l.session.set("ow_aem_loginstate", "logged_in", !1) : l.session.set("ow_aem_loginstate", "logged_out", !1);
}
const s = c.createLogger("FLOW-RUNNER");
class O {
  constructor(t, n, i) {
    e(this, "actionName");
    e(this, "importPrefix", "@b2x/loginaction/");
    e(this, "importMap");
    e(this, "loginData");
    e(this, "importMapActionUrl");
    var g;
    this.actionName = t, this.importMap = i, this.loginData = n, this.importMapActionUrl = (g = this.importMap) == null ? void 0 : g.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 s.info(`Checking condition for action: ${this.actionName}`, i ? "🚧" : "❌"), i;
  }
  async runAction() {
    await (await import(
      /* @vite-ignore */
      this.importMapActionUrl
    )).default(this.loginData), s.info(` ✅ Executed action: ${this.actionName}`);
  }
  async run() {
    s.info(`🚀 Running action: ${this.actionName}`);
    try {
      await this.runCondition() && await this.runAction();
    } catch (t) {
      s.warn(`⛔️ Error running condition or action: ${this.actionName}`, t);
    }
  }
}
async function U(o, t) {
  const n = M();
  for (const i of o)
    n.imports[`@b2x/loginaction/${i}`] && await new O(i, t, n).run();
}
const R = c.createLogger("FLOW"), x = ["declarationOfConsent", "checkForConsentUpdates"], r = ["checkNationalConsentStatus", "checkForConsentUpdates"], u = {
  ba: null,
  rs: null,
  hk: r,
  jp: r,
  kr: r,
  la: r,
  mo: r,
  my: r,
  sg: r,
  vn: r,
  standard: x
};
function P(o) {
  const t = l.local.get("b2x.lal_flow");
  return t ? (R.warn("Using custom flow", t), t) : u[o] || u.standard;
}
const _ = c.createLogger("BOOTSTRAP");
async function v(o, t) {
  try {
    const n = P(o.toLowerCase()), i = C(t, o);
    await U(n, i), p("login-action:done", { country: o });
  } catch (n) {
    p("login-action:failed", { country: o }), _.error("Error initializing login actions library", n);
  }
}
const D = c.createLogger("BOOTSTRAP");
async function j() {
  D.info(`Login Actions library ${f} - ${d}`);
  const { country: o } = L().pageEnvironmentVariables, t = await S();
  k(t), t.isLoggedIn && v(o, t);
}
j();
//# sourceMappingURL=bootstrap.mjs.map
