import { defineApi as l } from "@b2x/std/public-api.mjs";
import { l as g, Q as t, P as u, F as p, g as E, C as n, a as S, T as R, n as f, r as h, b as m, c as P, d as A } from "./chunks/bootstrap.mjs";
import { BUSINESS_TYPE as C, subscribe as I } from "@b2x/profile-library";
const T = g.createLogger("REGISTER_CIAS");
async function b() {
  try {
    return (await new Promise((e) => {
      let a = () => {
      };
      a = I((r) => {
        a(), e(r);
      });
    }))?.activeProfile?.businessType || null;
  } catch (s) {
    return T.warn("Could not get business type from Profile Library", s), null;
  }
}
async function L({ isB2BRegistrationEnabled: s = !1 } = {}) {
  const e = new URL(globalThis.location.href);
  e.searchParams.append(t.PROVIDER, u.CIAS), e.searchParams.append(t.FLOW, p.LOGIN), e.searchParams.append(t.REGISTER, "true");
  const { country: a, language: r } = await E(), i = {
    redirectUrl: e.toString(),
    tenantId: R.ONEWEB,
    locale: `${r}_${a}`
  };
  if (s) {
    const c = await b() === C.B2B ? n.ENABLED : n.DISABLED;
    i[t.B2B_REGISTRATION] = c;
  }
  const o = new URL("registration", await S());
  o.search = new URLSearchParams(i).toString(), f(o);
}
const d = l({
  owner: "iam",
  store: A,
  publicApis: {
    loginCias: P,
    logoutCias: m,
    registerCias: L,
    refreshAuthentication: h
  }
}), {
  loginCias: w,
  logoutCias: y,
  registerCias: B,
  refreshAuthentication: $,
  subscribeIam: v,
  useIamReactiveState: D
} = d, F = w, G = y, W = B;
export {
  F as login,
  w as loginCias,
  G as logout,
  y as logoutCias,
  $ as refreshAuthentication,
  W as register,
  B as registerCias,
  v as subscribeIam,
  D as useIamReactiveState
};
//# sourceMappingURL=index.mjs.map
