import e, { useState as U, useEffect as q } from "react";
import { IamHelper as ue, IamUserAuthorizationClient as $, LoginErrorExpired as Xe, LoginErrorCancelled as qe, TWOFA_PAGE as x, Iam as $e, EligibleUser as et } from "@accelbyte/sdk-iam";
import { d as G, u as he, e as Se, D as tt, b as at, c as it, f as nt, g as je, a as ot, A as rt } from "./index-28007ca6.mjs";
import { e as B, h as ne, t as C, B as Q, j as st, k as ct, f as Ae, b as lt, a as Mt } from "./useRoutes-367960a3.mjs";
import { C as F } from "./CommonError-b56f12ad.mjs";
import { a as ge, b as xe } from "./LoadingPage-d6d2cc0b.mjs";
import { u as ee, c as V, E as Z, A as ut, F as b, b as Ee } from "./Env-92498313.mjs";
import { Trans as n, useTranslation as gt } from "react-i18next";
import { LegalHelper as me } from "@accelbyte/sdk-legal";
import { A as K } from "./Alert-98fe02c6.mjs";
import { H as mt } from "./HeaderAlerts-ad49aa54.mjs";
import { A as dt, B as It, E as Nt, u as pe, V as de, a as ke, b as yt, H as Ce, c as Dt, d as Et, e as jt, U as At, I as pt, L as Ct } from "./EmailVerificationForm-41f9782b.mjs";
import { A as h } from "./Alert-1277e378.mjs";
import { z as le } from "zod";
import { C as zt } from "./Checkbox-001b1e04.mjs";
import Ne from "react-otp-input";
import { u as ze } from "./useHeaderAlerts-206faff0.mjs";
import { DesktopChecker as Tt } from "@accelbyte/sdk";
import { u as ft } from "./useCompanyLogo-e4bed311.mjs";
import Me from "classnames";
import { a as Pe, F as we } from "./Select-934e9e99.mjs";
import { I as Oe } from "./InputGroup-b546018b.mjs";
import { f as _e, i as be, g as ve, e as X } from "./validateNotEmpty-815360bd.mjs";
import { b as Ue } from "./numbers-bf855d8f.mjs";
import { L as Lt } from "./LanguageSelector-f4c332fb.mjs";
import ht from "js-cookie";
import { s as St, N as xt } from "./NetworkError-e8e9ffd0.mjs";
import "react-dom";
import "react-feather";
import "buffer";
import "react-toastify";
import "@accelbyte/sdk-gdpr";
import "@accelbyte/sdk-basic";
import "flat";
import "i18next";
import "date-fns";
import "./utils.mjs";
import "uuid";
import "./ErrorLayout-d232f96c.mjs";
import "axios";
import "./InfoIcon-c86fd057.mjs";
import "shortid";
import "@zxcvbn-ts/core";
import "./PageRoute-835113de.mjs";
import "react-router";
import "./CircleCheckIcon-8f97f219.mjs";
import "./InputLabel-760cfc94.mjs";
import "react-select";
import "react-tooltip";
import "./merge-78dc87d6.mjs";
import "xregexp";
const kt = "errorContainer _errorContainer_e813d", Pt = "sessionExpiredContainer _sessionExpiredContainer_3487b", wt = "codeExchangeloader _codeExchangeloader_9bd96", Ye = {
  errorContainer: kt,
  sessionExpiredContainer: Pt,
  codeExchangeloader: wt
}, Ot = (t) => {
  const [a, i] = U(null), [o] = ee(), { state: r } = B(), { state: l } = ne(), { mutations: M } = V(), s = G();
  q(() => {
    g();
  }, []);
  const y = () => {
    var m;
    r.replace(`${(m = r.location) == null ? void 0 : m.pathname}`);
  }, g = async () => {
    try {
      await N(), t.onAuthCodeDone();
    } catch (m) {
      console.error(m), y(), i(m);
    }
  }, N = async () => {
    var u, E;
    if (!((u = r.location) != null && u.search))
      return;
    const { code: m, error: p, state: d } = ue.getAuthorizationCodeParams((E = r.location) == null ? void 0 : E.search);
    try {
      const f = await new $(o).exchangeAuthorizationCode({
        code: m,
        error: p,
        state: d
      });
      if (!f)
        return;
      y();
      const { mfaData: P, returnPath: j } = f;
      P ? M.updateMFAData(P) : await s.fetchAllUserInformation(), j ? r.replace(j) : r.replace(l.home.link);
    } catch (z) {
      t.onAuthCodeError(z);
    }
  };
  return /* @__PURE__ */ e.createElement(e.Fragment, null, !a && /* @__PURE__ */ e.createElement("div", { className: Ye.codeExchangeloader }, /* @__PURE__ */ e.createElement(ge, { className: xe.medium }, /* @__PURE__ */ e.createElement(n, { i18nKey: "InitialUserFetchPage.notice" }))), a && /* @__PURE__ */ e.createElement(_t, { error: a }));
}, _t = ({ error: t }) => {
  var r;
  const { state: a } = B(), [i] = ee(), o = () => {
    const l = new $(i).createLoginURL(a.location.pathname);
    window.location.replace(l);
  };
  if (!t)
    return null;
  if (Z.isAxiosError(t) && ((r = t == null ? void 0 : t.response) != null && r.status)) {
    const { status: l } = t.response;
    if (l === 400)
      return /* @__PURE__ */ e.createElement(e.Fragment, null);
    if (l === 401)
      return /* @__PURE__ */ e.createElement("div", { className: Ye.sessionExpiredContainer }, /* @__PURE__ */ e.createElement(n, { i18nKey: "AuthorizationCodeExchanger.error.sessionExpired" }, "Session Expired"), /* @__PURE__ */ e.createElement("div", { onClick: o }, C("HomePage.login")));
  }
  return /* @__PURE__ */ e.createElement(F, { error: t });
}, Yi = ({ children: t }) => {
  var m;
  const [a, i] = U(!1), {
    state: o,
    mutations: { setLocation: r }
  } = B(), { state: l } = ne(), M = G(), [s] = ee(), g = new URLSearchParams((m = o.location) == null ? void 0 : m.search).get("error"), N = (p) => {
    var u;
    const d = { ...o.location, search: "" };
    if (r(d), p instanceof Xe)
      return M.logout(), o.replace(l["error.sessionExpired"].link);
    if (p instanceof qe)
      return o.replace(`${(u = o.location) == null ? void 0 : u.pathname}`);
    throw p;
  };
  if (!s)
    return null;
  if (g) {
    const p = $.deduceLoginError(g);
    return N(p), null;
  }
  return a ? t : /* @__PURE__ */ e.createElement(Ot, { onAuthCodeDone: () => i(!0), onAuthCodeError: N });
};
const bt = typeof Ne == "object" ? Ne.default : Ne;
class vt extends e.Component {
  constructor(a) {
    super(a), this.onCodeChange = (i) => {
      this.setState({ code: i });
    }, this.onRememberDeviceChange = () => {
      this.setState((i) => ({
        rememberDevice: !i.rememberDevice
      }));
    }, this.submit = () => {
      const { factor: i } = this.props, { code: o, rememberDevice: r } = this.state;
      this.props.onSubmit({ code: o, factor: i, rememberDevice: r });
    }, this.onKeyDown = (i) => {
      i.key !== "Enter" || this.state.code.length < this.props.codeLength || this.submit();
    }, this.state = {
      code: "",
      rememberDevice: !0
    };
  }
  componentDidMount() {
    window.addEventListener("keydown", this.onKeyDown);
  }
  componentWillUnmount() {
    window.removeEventListener("keydown", this.onKeyDown);
  }
  render() {
    const { codeLength: a, isSubmitting: i, onTryAnother: o, helperText: r } = this.props, { code: l, rememberDevice: M } = this.state;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
      bt,
      {
        value: l,
        onChange: this.onCodeChange,
        numInputs: a,
        className: "otpInput",
        containerStyle: "otpInputContainer",
        focusStyle: "otpInput__focus",
        shouldAutoFocus: !0,
        isDisabled: i
      }
    ), r, /* @__PURE__ */ e.createElement("div", { className: "rememberDeviceContainer" }, /* @__PURE__ */ e.createElement(zt, { isChecked: M, onChange: this.onRememberDeviceChange, label: C("twoFAPage.checkbox.rememberDevice") }), !!o && /* @__PURE__ */ e.createElement("span", { className: "tryAnother", onClick: o }, /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.tryAnother" }, "Try another way"))), /* @__PURE__ */ e.createElement(
      Q,
      {
        loadingIndicator: "SPINNER",
        className: "continueButton btn btn-primary",
        onClick: this.submit,
        disabled: l.length < a,
        isLoading: i
      },
      C("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.continue")
    ));
  }
}
const ye = (t) => {
  const { icon: a, description: i, onClick: o } = t;
  return /* @__PURE__ */ e.createElement("div", { className: "methodOption", onClick: o }, a, /* @__PURE__ */ e.createElement("p", null, i));
}, re = (t) => {
  const { title: a, alert: i, withAlert: o, description: r, children: l, onDismissAlert: M } = t;
  return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "titleWrapper" }, /* @__PURE__ */ e.createElement("p", { className: "title" }, a), !!i && o && /* @__PURE__ */ e.createElement(K, { type: i.type, onDismiss: M, className: "text-left" }, i.element), /* @__PURE__ */ e.createElement("p", { className: "description" }, r)), l);
}, se = "mfaPage", Ut = 6, Yt = 8, Qt = 6, ce = le.enum(["invalid_code", "invalid_factor", "invalid_mfa_token", "code_expired"]), Vt = le.object({
  error: le.string(),
  error_description: le.string()
}), Ft = (t) => {
  switch (t) {
    case "backupCode":
      return /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.error.invalidBackupCode" }, "Sorry, the backup code you entered is invalid. Please try again.");
    case "authenticator":
      return /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.error.invalidAuthCode" }, "Sorry, the 6-digits authentication code you entered is invalid. Please try again.");
    default:
      return /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.error.invalidCode" }, "Sorry, the 6-digits verification code you entered is invalid. Please try again.");
  }
}, Gt = (t, a) => {
  var i;
  try {
    if (Z.isAxiosError(t))
      switch (Vt.parse((i = t == null ? void 0 : t.response) == null ? void 0 : i.data).error) {
        case ce.Enum.invalid_code:
          return Ft(a);
        case ce.Enum.code_expired:
          return /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.error.codeExpired" }, "Sorry, the code you entered is expired. Please try again.");
        case ce.Enum.invalid_factor:
        case ce.Enum.invalid_mfa_token:
          return /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.error.invalidFactor" }, "Failed to complete the request. Please click the back to login button below, and try logging in again.");
      }
    throw t;
  } catch {
    return /* @__PURE__ */ e.createElement(F, { error: t });
  }
}, Rt = () => {
  var J, A;
  const [t, a] = U(), [i, o] = U(!1), [r, l] = U(!0), [M, s] = U(), [y] = ee(), { state: g } = B(), { state: N, mutations: m } = V(), { mutations: p } = ze(), d = G(), {
    mutations: { fetchLoginConfigs: u }
  } = he(), { companyLogo: E } = ft(ut.LOGIN, "header"), z = ((J = N.mfaData) == null ? void 0 : J.factors) || [];
  q(() => {
    var _;
    f();
    const c = (_ = N.mfaData) == null ? void 0 : _.defaultFactor, D = sessionStorage.getItem(se);
    a(D || c || x.enum.options);
  }, []);
  const f = async () => {
    try {
      await u();
    } catch (c) {
      console.error(c);
    } finally {
      l(!1);
    }
  }, P = (c) => {
    a(c), sessionStorage.setItem(se, c);
  }, j = () => {
    P(x.enum.options);
  }, T = () => {
    s(null);
  }, w = async (c) => {
    if (!i)
      try {
        o(!0);
        const D = await m.verify2FA(c);
        if (D) {
          if (D.error)
            throw D.error;
          d.refreshSession(D.data.access_token, D.data.refresh_token), await d.refreshUser(), sessionStorage.removeItem(se), m.removeMFAData(), N.isLinkingAccountRequired2FA && (p.push({
            type: h.success,
            element: /* @__PURE__ */ e.createElement(n, { i18nKey: "LinkPlatformAccountPage.notification.accountLinked" }, "Account linked")
          }), m.clearLinkAccountRequired2FA());
        }
      } catch (D) {
        if (Z.isAxiosNetworkError(D)) {
          p.push({
            type: h.danger,
            element: C("CommonError.networkError")
          });
          return;
        }
        const _ = Gt(D, t);
        s({ type: h.danger, element: _ });
      } finally {
        o(!1);
      }
  }, O = async (c) => {
    if (!(i || !N.mfaData))
      try {
        o(!0), await $e.OAuth20Api(y).postOauthMfaCode({
          mfaToken: N.mfaData.mfaToken,
          factor: "email",
          clientId: y.assembly().clientId
        }), c && s({ type: h.success, element: C("twoFAPage.email.resend.success") }), a(x.enum.email);
      } catch (D) {
        if (Z.isAxiosNetworkError(D)) {
          p.push({
            type: h.danger,
            element: C("CommonError.networkError")
          });
          return;
        }
        s({ type: h.danger, element: /* @__PURE__ */ e.createElement(F, { error: D }) });
      } finally {
        o(!1);
      }
  }, R = (c) => {
    switch (c) {
      case x.enum.backupCode:
        return Yt;
      case x.enum.authenticator:
        return Ut;
      default:
        return Qt;
    }
  }, te = () => /* @__PURE__ */ e.createElement("div", { className: "mt-3 text-[13px]" }, /* @__PURE__ */ e.createElement("span", null, C("AccountPasswordSecurity.2fa.emailModal.helperText")), /* @__PURE__ */ e.createElement("span", { className: "ml-1 cursor-pointer text-blue-50", onClick: () => O(!0) }, C("AccountPasswordSecurity.2fa.emailModal.resendBtn"))), L = (c, D) => {
    var oe;
    const _ = ((oe = N.mfaData) == null ? void 0 : oe.factors) || [];
    return /* @__PURE__ */ e.createElement(
      vt,
      {
        onTryAnother: _.length > 1 ? j : void 0,
        codeLength: R(c),
        factor: c,
        onSubmit: w,
        isSubmitting: i,
        helperText: D
      }
    );
  }, H = () => {
    if (sessionStorage.removeItem(se), m.removeMFAData(), d.logout(), !Tt.isDesktopApp()) {
      const c = new $(y).createLoginURL(g.location.pathname);
      window.location.replace(c);
    }
  };
  return /* @__PURE__ */ e.createElement("div", { className: "twoFAPage" }, /* @__PURE__ */ e.createElement(mt, { className: "twoFAAlert" }), /* @__PURE__ */ e.createElement("div", { className: "twoFAContainer" }, /* @__PURE__ */ e.createElement("div", { className: "flex justify-center" }, !r && /* @__PURE__ */ e.createElement("img", { src: E, loading: "lazy" })), /* @__PURE__ */ e.createElement("div", { className: "twoFAForm" }, t === x.enum.authenticator && /* @__PURE__ */ e.createElement(
    re,
    {
      title: C("twoFAPage.authenticator.title"),
      description: /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.authenticator.description" }, "Please enter the security code from your authenticator app."),
      withAlert: !0,
      alert: M,
      onDismissAlert: T
    },
    L(x.enum.authenticator)
  ), t === x.enum.backupCode && /* @__PURE__ */ e.createElement(
    re,
    {
      title: C("twoFAPage.backupCode.title"),
      description: /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.backupCode.description" }, "Please enter one of your backup codes to continue."),
      withAlert: !0,
      alert: M,
      onDismissAlert: T
    },
    L(x.enum.backupCode)
  ), t === x.enum.email && /* @__PURE__ */ e.createElement(
    re,
    {
      title: C("twoFAPage.email.title"),
      description: /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.email.description" }, "To continue, please enter the 6-digits verification code we’ve sent to your email at", /* @__PURE__ */ e.createElement("strong", null, { email: (A = N.mfaData) == null ? void 0 : A.email }), ".", /* @__PURE__ */ e.createElement("a", { href: "https://docs.accelbyte.io/faq/faq.html", target: "_blank", rel: "noreferrer" }, "Learn more")),
      withAlert: !0,
      alert: M,
      onDismissAlert: T
    },
    L(x.enum.email, te())
  ), t === x.enum.options && /* @__PURE__ */ e.createElement(re, { title: C("twoFAPage.verify.title"), description: C("twoFAPage.verify.description") }, !!M && /* @__PURE__ */ e.createElement(K, { type: M.type, onDismiss: T, className: "text-left" }, M.element), z.includes(x.enum.authenticator) && /* @__PURE__ */ e.createElement(
    ye,
    {
      icon: /* @__PURE__ */ e.createElement(dt, null),
      description: C("twoFAPage.verify.authApp.description"),
      onClick: () => P(x.enum.authenticator)
    }
  ), z.includes(x.enum.backupCode) && /* @__PURE__ */ e.createElement(
    ye,
    {
      icon: /* @__PURE__ */ e.createElement(It, null),
      description: C("twoFAPage.verify.backupCode.description"),
      onClick: () => P(x.enum.backupCode)
    }
  ), z.includes(x.enum.email) && /* @__PURE__ */ e.createElement(
    ye,
    {
      icon: /* @__PURE__ */ e.createElement(Nt, null),
      description: C("twoFAPage.verify.email.description"),
      onClick: () => O(!1)
    }
  ))), /* @__PURE__ */ e.createElement("div", { className: "backContainer" }, /* @__PURE__ */ e.createElement("button", { onClick: H }, /* @__PURE__ */ e.createElement(n, { i18nKey: "twoFAPage.backToLogin" }, "Back to Login")))));
};
const Wt = () => {
  var d;
  const [t, a] = U(null), i = G(), { state: o } = V(), { state: r, mutations: l } = Se(), { mutations: M } = ze(), s = r.requestDeletionFetchStatus === b.CANCELLING, y = (d = r.gdprDeletionStatus) == null ? void 0 : d.DeletionDate, g = async () => {
    M.push({
      type: h.success,
      element: /* @__PURE__ */ e.createElement(n, { i18nKey: "AccountDeletionNoticePage.cancelAccountDeletionSuccess" }, "The account deletion process has been cancelled. Please log in to continue."),
      autoDismiss: !0
    }), i.clear();
  }, N = (u) => {
    a({
      type: h.danger,
      element: /* @__PURE__ */ e.createElement(F, { error: u })
    });
  }, m = async () => {
    const u = o.user;
    if (u)
      try {
        await l.cancelDeleteAccount(u.userId), g(), await i.logout();
      } catch (E) {
        N(E);
      }
  }, p = async () => {
    await i.logout();
  };
  return /* @__PURE__ */ e.createElement("div", { className: "deletionNoticeContainer" }, /* @__PURE__ */ e.createElement("main", null, !!t && !s && /* @__PURE__ */ e.createElement(K, { type: t.type, className: "alert", onDismiss: () => a(null) }, t.element), /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "common.AccountDeletion.title" }, "Account deletion in-progress")), /* @__PURE__ */ e.createElement("div", { className: "content" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "common.AccountDeletion.content" }, "Your account is set to be deleted on ", { deletionDate: y }, ". Please check your email for more information regarding the deletion request.")), /* @__PURE__ */ e.createElement("div", { className: "btnContainer" }, /* @__PURE__ */ e.createElement("button", { className: "btn big btnContinue", onClick: () => p() }, /* @__PURE__ */ e.createElement(n, { i18nKey: "AccountDeletionNoticePage.button.keepDeleting" }, "Continue the Deletion")), /* @__PURE__ */ e.createElement("button", { className: "btn big btn-primary btnCancel", disabled: s, onClick: () => m() }, s && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(st, { className: `${ct.inline} spinner` }), /* @__PURE__ */ e.createElement(n, { i18nKey: "AccountDeletionNoticePage.form.processing" }, "Processing...")), !s && /* @__PURE__ */ e.createElement(n, { i18nKey: "AccountDeletionNoticePage.button.cancelDeletion" }, "Cancel Deletion")))));
}, Ht = "emailVerificationPage _emailVerificationPage_56356", Zt = "emailVerificationPageContainer _emailVerificationPageContainer_2fd38", Bt = "logoContainer _logoContainer_124fd", Kt = "emailVerificationPageHeader _emailVerificationPageHeader_64552", Jt = "emailVerificationPageForm _emailVerificationPageForm_6a65a", Xt = "title _title_0a6c1", qt = "description _description_40202", $t = "input _input_b1973", v = {
  emailVerificationPage: Ht,
  emailVerificationPageContainer: Zt,
  logoContainer: Bt,
  emailVerificationPageHeader: Kt,
  emailVerificationPageForm: Jt,
  title: Xt,
  description: qt,
  input: $t
}, ea = "logoutConfirmationModal _logoutConfirmationModal_41a86", ta = {
  logoutConfirmationModal: ea
}, aa = ({ onLogout: t, onClose: a, isOpen: i }) => /* @__PURE__ */ e.createElement(tt, { title: C("LogoutConfirmationModal.title"), isOpen: i, className: Me(ta.logoutConfirmationModal) }, /* @__PURE__ */ e.createElement(at, null, /* @__PURE__ */ e.createElement("p", null, C("LogoutConfirmationModal.content"))), /* @__PURE__ */ e.createElement(it, { className: "dialogFooter" }, /* @__PURE__ */ e.createElement(Q, { className: "btn big btn-ghost btnClose footer-btn", onClick: a }, C("UserSessionList.dialog.cancel")), /* @__PURE__ */ e.createElement(Q, { className: "btn big btn-primary btnLogout footer-btn", onClick: t }, C("UserSessionList.dialog.logout")))), ia = () => {
  const t = e.useRef(new _e()), [a, i] = U({
    verificationCode: "",
    alert: null,
    isVerificationSuccess: !1,
    isPasteVerificationCode: !1
  }), { state: o } = V(), { state: r, mutations: l } = pe(), M = G(), { mutations: s } = ze(), y = r.fetchVerificationStatus === b.VERIFYING, g = r.fetchVerificationStatus === b.REQUESTING, N = !t.current.isAllValid() || be(a.verificationCode) || y || a.isVerificationSuccess, m = (j, T) => {
    i((w) => ({
      ...w,
      alert: { type: j, element: T }
    }));
  }, p = async () => {
    i((j) => ({
      ...j,
      isVerificationSuccess: !0
    })), s.push({
      type: h.success,
      element: /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.accountVerified" }, "Congratulations! The registration process is complete."),
      autoDismiss: !0
    }), await M.refreshUser();
  }, d = async (j) => {
    const T = await l.verify(j, Ae());
    if (T.error) {
      m(h.danger, /* @__PURE__ */ e.createElement(F, { error: T.error }));
      return;
    }
    p();
  }, u = () => {
    M.logout();
  }, E = (j) => {
    const { isPasteVerificationCode: T } = a, w = j.target.value.toString().toUpperCase(), O = T ? w.replace(/\s/g, "") : w;
    t.current.set("verificationCode", ve(O)), i((R) => ({
      ...R,
      verificationCode: O,
      isPasteVerificationCode: !1
    }));
  }, z = () => {
    i((j) => ({
      ...j,
      isPasteVerificationCode: !0
    }));
  }, f = (j) => {
    if (!j)
      return null;
    const T = {
      [X.enum.empty]: /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.verifyCodeForm.verifyCodeError.empty" }, "Please enter your verification code."),
      [X.enum.exceedLengthLimit]: /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.verifyCodeForm.verifyCodeError.ExceedLimit" }, "Verification code must not exceed ", { MAX_SHORT_TEXT_LENGTH: Ue }, " characters"),
      [X.enum.invalidFormat]: /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.verifyCodeForm.verifyCodeError.invalidFormat" }, "The verification code must be alphanumeric and cannot contain spaces or special characters.")
    };
    return /* @__PURE__ */ e.createElement(we, null, T[j]);
  }, P = async () => {
    var w;
    const j = ((w = o.user) == null ? void 0 : w.emailAddress) || "", T = await l.sendVerificationCode(j, de.enum.UserAccountRegistration);
    if (T.error) {
      m(h.danger, /* @__PURE__ */ e.createElement(F, { error: T.error }));
      return;
    }
    m(
      h.success,
      /* @__PURE__ */ e.createElement(n, { i18nKey: "ChangeEmailPage.verifyCodeForm.codeSent" }, "A verification code has been sent to your email")
    );
  };
  return /* @__PURE__ */ e.createElement("div", { className: "newEmailVerification" }, /* @__PURE__ */ e.createElement("div", { className: v.title }, /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.title" }, "Enter the Verification Code")), !!a.alert && /* @__PURE__ */ e.createElement(
    K,
    {
      className: "mb-6",
      type: a.alert.type,
      onDismiss: () => i((j) => ({
        ...j,
        alert: null
      }))
    },
    a.alert.element
  ), /* @__PURE__ */ e.createElement("div", { className: v.description }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.instruction1" }, "A verification code has been sent to your email. Please verify your email address to complete the registration process.")), /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.instruction2" }, "Please enter the verification code below:"))), /* @__PURE__ */ e.createElement(Pe, null, /* @__PURE__ */ e.createElement(
    Oe,
    {
      className: v.input,
      value: a.verificationCode || "",
      placeholder: C("EmailVerificationPage.placeholder.verificationCode"),
      onChange: E,
      onPaste: z
    }
  ), f(t.current.get("verificationCode"))), /* @__PURE__ */ e.createElement("div", { className: v.description }, /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.sendVerificationCode.didntReceiveEmail" }, "Didn't receive an email?"), g && /* @__PURE__ */ e.createElement("span", { className: "ml-1" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.sendVerificationCode.requesting" }, "Requesting..")), !g && /* @__PURE__ */ e.createElement("span", { onClick: P }, /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.sendVerificationCode.click" }, " Click here to resend"))), /* @__PURE__ */ e.createElement("div", { className: "flex flex-row" }, /* @__PURE__ */ e.createElement(
    Q,
    {
      loadingIndicator: "SPINNER",
      disabled: N,
      className: "btn big btn-primary mt-6 mr-2 uppercase",
      onClick: () => d(a.verificationCode),
      isLoading: y
    },
    /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.submitButton" }, "VERIFY")
  ), /* @__PURE__ */ e.createElement(Q, { className: "btn big text-blue-40 mt-6 capitalize", onClick: u, disabled: y || a.isVerificationSuccess }, /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.notNowBtn" }, "Not Now"))));
};
class na extends e.Component {
  constructor(a) {
    super(a), this.onVerificationCodeChange = (i) => {
      const o = i.target.value.toString().toUpperCase();
      this.validation.set("verificationCode", ve(o)), this.setState({
        verificationCode: o
      });
    }, this.state = {
      verificationCode: ""
    }, this.validation = new _e(), this.validation.listen(() => this.setState({}));
  }
  renderVerificationCodeError(a) {
    if (!a)
      return null;
    const i = {
      [X.enum.empty]: /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.verifyCodeForm.verifyCodeError.empty" }, "Please enter your verification code."),
      [X.enum.exceedLengthLimit]: /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.verifyCodeForm.verifyCodeError.ExceedLimit" }, "Verification code must not exceed ", { MAX_SHORT_TEXT_LENGTH: Ue }, " characters"),
      [X.enum.invalidFormat]: /* @__PURE__ */ e.createElement(n, { i18nKey: "EmailVerificationPage.verifyCodeForm.verifyCodeError.invalidFormat" }, "The verification code must be alphanumeric and cannot contain spaces or special characters.")
    };
    return /* @__PURE__ */ e.createElement(we, null, i[a]);
  }
  render() {
    const { isRequestingCode: a, isVerifying: i, onChangeEmail: o, onResend: r, onVerify: l, alert: M, onDismissAlert: s, isSuccess: y } = this.props, { verificationCode: g } = this.state, N = be(g) || i || y || !this.validation.isAllValid();
    return /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement("div", { className: v.title }, /* @__PURE__ */ e.createElement(n, { i18nKey: "NewEmailVerificationPage.title" }, "Verify your new email")), !!M && /* @__PURE__ */ e.createElement(K, { type: M.type, onDismiss: s, className: "mb-6" }, M.element), /* @__PURE__ */ e.createElement("div", { className: v.description }, /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement(n, { i18nKey: "NewEmailVerificationPage.verificationCodeForm.description" }, "A verification code has been sent to your new email address. Please enter the verification code below."))), /* @__PURE__ */ e.createElement(Pe, null, /* @__PURE__ */ e.createElement(
      Oe,
      {
        className: v.input,
        value: g || "",
        placeholder: C("NewEmailVerificationPage.placeholder.verificationCode"),
        onChange: this.onVerificationCodeChange
      }
    ), this.renderVerificationCodeError(this.validation.get("verificationCode"))), /* @__PURE__ */ e.createElement("div", { className: "mt-2 flex flex-row" }, /* @__PURE__ */ e.createElement(
      Q,
      {
        loadingIndicator: "SPINNER",
        disabled: N,
        className: Me(v.btnActionVerify, "btn btn-primary"),
        onClick: () => l(g),
        isLoading: i
      },
      /* @__PURE__ */ e.createElement(n, { i18nKey: "NewEmailVerificationPage.submitButton" }, "Verify")
    )), /* @__PURE__ */ e.createElement("div", { className: Me(v.description, "mt-2") }, /* @__PURE__ */ e.createElement(n, { i18nKey: "NewEmailVerificationPage.sendVerificationCode.didntReceiveEmail" }, "Didn't receive the email?"), a && /* @__PURE__ */ e.createElement("span", { className: "ml-1" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "NewEmailVerificationPage.sendVerificationCode.requesting" }, "Requesting...")), !a && /* @__PURE__ */ e.createElement("span", { onClick: () => r() }, /* @__PURE__ */ e.createElement(n, { i18nKey: "NewEmailVerificationPage.sendVerificationCode.click" }, " Click here to resend"))), /* @__PURE__ */ e.createElement("div", { className: Me(v.description, "mt-2") }, /* @__PURE__ */ e.createElement(n, { i18nKey: "NewEmailVerificationPage.changeEmail" }, "Entered the wrong email?", /* @__PURE__ */ e.createElement("span", { onClick: () => o() }, " Click here to change"))));
  }
}
const oa = (t) => {
  const [a, i] = U({
    step: "verifyCodeNewEmail",
    verificationCode: "",
    alert: null,
    isVerificationSuccess: !1
  }), { state: o, mutations: r } = V(), { state: l, mutations: M } = pe(), { state: s, mutations: y } = ke(), { state: g } = B(), { state: N } = ne(), m = G();
  q(() => {
    var c;
    const A = new URLSearchParams((c = g.location) == null ? void 0 : c.search);
    p(), A.get("isChangingEmail") && i((D) => ({
      ...D,
      step: "inputNewEmail"
      /* inputNewEmail */
    }));
  }, []);
  const p = async () => {
    const A = await y.fetchValidations();
    A.error && E(A.error);
  }, d = (A) => {
    i((c) => ({
      ...c,
      ...A
    }));
  }, u = () => {
    d({
      alert: {
        type: h.success,
        element: /* @__PURE__ */ e.createElement(n, { i18nKey: "ChangeEmailPage.verifyCodeForm.codeSent" }, "A verification code has been sent to your email")
      }
    });
  }, E = async (A) => {
    s.validationsError && await y.refetchIfValidationError(s.validationsError), d({
      alert: {
        type: h.danger,
        element: /* @__PURE__ */ e.createElement(F, { error: A })
      }
    });
  }, z = async (A) => {
    const c = await M.verify(A, Ae());
    if (c.error) {
      d({
        alert: {
          type: h.danger,
          element: /* @__PURE__ */ e.createElement(F, { error: c.error })
        },
        isVerificationSuccess: !1
      });
      return;
    }
    d({ isVerificationSuccess: !0 }), await m.fetchAllUserInformation(), g.push({ pathname: N.account.profile.link, state: { updateEmailStatus: "success" } });
  }, f = () => {
    d({ alert: null });
  }, P = async () => {
    const { setIsLogoutAvailable: A } = t, c = o.user, D = (c == null ? void 0 : c.oldEmailAddress) || (c == null ? void 0 : c.emailAddress) || "", _ = await M.sendVerificationCode(D, de.enum.UpdateEmailAddress);
    _.error ? await E(_.error) : u(), d({
      step: "inputNewEmail"
      /* inputNewEmail */
    }), g.push(`${g.location.pathname}?isChangingEmail=true`), A(!1);
  }, j = () => {
    const { setIsLogoutAvailable: A } = t;
    d({
      step: "verifyCodeNewEmail"
      /* verifyCodeNewEmail */
    }), f(), g.push(g.location.pathname), A(!0);
  }, T = async (A, c) => {
    const { pathname: D } = g.location, _ = await r.updateEmail(A, c);
    if (_.error) {
      E(_.error);
      return;
    }
    window.open(D, "_self");
  }, w = async (A) => {
    const c = await M.sendVerificationCode(A, de.enum.UpdateEmailAddress);
    if (c.error) {
      E(c.error);
      return;
    }
    u();
  }, O = et.safeParse(o.user);
  if (!O.success)
    return null;
  const R = O.data.newEmailAddress || O.data.emailAddress, te = O.data.emailVerified, L = O.data.oldEmailAddress || O.data.emailAddress, H = l.fetchVerificationStatus === b.REQUESTING, J = l.fetchVerificationStatus === b.VERIFYING;
  return /* @__PURE__ */ e.createElement("div", { className: "newEmailVerification" }, a.step === "verifyCodeNewEmail" && /* @__PURE__ */ e.createElement(
    na,
    {
      isRequestingCode: H,
      isVerifying: J,
      onResend: () => w(R),
      onVerify: async (A) => {
        await z(A);
      },
      onChangeEmail: P,
      alert: a.alert,
      onDismissAlert: f,
      isSuccess: a.isVerificationSuccess
    }
  ), a.step === "inputNewEmail" && /* @__PURE__ */ e.createElement(
    yt,
    {
      isRequestingCode: H,
      onResendCode: () => w(L),
      onUpdateEmail: T,
      alert: a.alert,
      onDismissAlert: f,
      oldEmail: L,
      isUpdatingEmail: o.userFetchStatus === b.UPDATING,
      isFromEmailVerification: !0,
      onCancel: j,
      emailVerified: te,
      newEmail: R
    }
  ));
}, ra = () => {
  const t = G(), { state: a } = V(), [i, o] = U({
    isLogoutAvailable: !0,
    isLogoutConfirmationModalOpen: !1,
    isUpdatingEmail: ue.currentUserIsUpdatingEmail(a.user)
  }), r = (s) => {
    o((y) => ({ ...y, isLogoutAvailable: s }));
  }, l = () => {
    o((s) => ({ ...s, isLogoutConfirmationModalOpen: !s.isLogoutConfirmationModalOpen }));
  }, M = () => {
    t.logout();
  };
  return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: v.emailVerificationPage }, /* @__PURE__ */ e.createElement("div", { className: v.emailVerificationPageContainer }, /* @__PURE__ */ e.createElement(Ce, null), /* @__PURE__ */ e.createElement("div", { className: v.emailVerificationPageForm }, i.isUpdatingEmail && /* @__PURE__ */ e.createElement(oa, { setIsLogoutAvailable: r }), !i.isUpdatingEmail && /* @__PURE__ */ e.createElement(ia, null)), i.isUpdatingEmail && i.isLogoutAvailable && /* @__PURE__ */ e.createElement("span", { onClick: l }, /* @__PURE__ */ e.createElement(n, { i18nKey: "UserSessionItem.logout" }, "Logout")))), /* @__PURE__ */ e.createElement(aa, { isOpen: i.isLogoutConfirmationModalOpen, onLogout: M, onClose: l }));
}, sa = "logoContainer _logoContainer_52753", ca = "headlessAccountPage _headlessAccountPage_2ca59", la = "headlessAccountPageContainer _headlessAccountPageContainer_d96d2", Ma = "headlessAccountPageContainerForm _headlessAccountPageContainerForm_67b05", ua = "headlessAgeBlockedContainerForm _headlessAgeBlockedContainerForm_8ab75", ga = "contentWrapper _contentWrapper_81569", ma = "formWrapper _formWrapper_9ffa0", da = "alert _alert_f9516", Ia = "passwordValidation _passwordValidation_558c7", Na = "flexCol _flexCol_d2b4e", ya = "passwordMismatch _passwordMismatch_0e3f5", Da = "title _title_18ef5", Ea = "description _description_bf661", ja = "resendCode _resendCode_c9e57", Aa = "tabs _tabs_9a914", pa = "tab _tab_87b89", Ca = "active _active_eafae", za = "label _label_b5606", Ta = "input _input_72094", fa = "select _select_3a03e", La = "datePicker _datePicker_bea4a", ha = "agreementList _agreementList_ce9dd", Sa = "agreementItem _agreementItem_ae90a", xa = "text _text_e917f", ka = "optional _optional_47629", Pa = "changePage _changePage_f89b9", wa = "backToHomepage _backToHomepage_d2be1", Oa = "backContainer _backContainer_fbe74", Y = {
  logoContainer: sa,
  headlessAccountPage: ca,
  headlessAccountPageContainer: la,
  headlessAccountPageContainerForm: Ma,
  headlessAgeBlockedContainerForm: ua,
  contentWrapper: ga,
  formWrapper: ma,
  alert: da,
  passwordValidation: Ia,
  flexCol: Na,
  passwordMismatch: ya,
  title: Da,
  description: Ea,
  resendCode: ja,
  tabs: Aa,
  tab: pa,
  active: Ca,
  label: za,
  input: Ta,
  select: fa,
  datePicker: La,
  agreementList: ha,
  agreementItem: Sa,
  text: xa,
  optional: ka,
  changePage: Pa,
  backToHomepage: wa,
  backContainer: Oa
}, De = "registration_email", _a = () => {
  var Te;
  const [t, a] = U({
    email: "",
    alert: null,
    displayedPolicies: [],
    step: "email",
    loginData: null
  }), { displayedPolicies: i, alert: o, step: r, email: l, loginData: M } = t, { state: s, mutations: y } = V(), { state: g, mutations: N } = pe(), { state: m, mutations: p } = nt(), { state: d, mutations: u } = ke(), { state: E, mutations: z } = je(), { state: f } = ot(), P = G(), [j] = ee(), { i18n: T } = gt(), {
    mutations: { fetchLoginConfigs: w }
  } = he(), { state: O, mutations: R } = Dt(), te = ((Te = f.discoveryConfigData) == null ? void 0 : Te.brandName.data.value) || "", L = (I) => {
    a((k) => ({
      ...k,
      ...I
    }));
  }, H = async () => {
    const I = await u.fetchValidations(Ae());
    I.error && D(I.error);
  };
  q(() => (J(), () => {
    ae();
  }), []);
  const J = async () => {
    var ie, W;
    const I = await w();
    if (L({ loginData: (ie = I.data) == null ? void 0 : ie.ageGating.data }), ht.get(rt.RETRY_DURATION_COOKIE_KEY) && ((W = I.data) == null ? void 0 : W.ageGating.data.value.isDelayedEnabled)) {
      P.logout(), ae(), We();
      return;
    }
    H();
    const S = sessionStorage.getItem(De);
    L({ email: S || "" }), A(), S && L({
      step: "otherData"
      /* otherData */
    });
  }, A = async () => {
    await R.fetchCurrentLocationCountry();
  };
  q(() => {
    var k, S;
    const I = ((k = s.user) == null ? void 0 : k.country) || ((S = O.currentCountryLocation) == null ? void 0 : S.countryCode);
    I && (async () => {
      const W = await z.fetchPoliciesList(I);
      if (W.error) {
        D(W.error);
        return;
      }
      L({ displayedPolicies: me.convertPoliciesToDisplayedPolicies(W.data || [], Ee.NAMESPACE) });
    })();
  }, [s.user, z.fetchPoliciesList]);
  const c = async (I = t.email) => {
    if (!I)
      return;
    const k = await N.sendVerificationCode(I, de.enum.upgradeHeadlessAccount);
    if (k.error) {
      D(k.error);
      return;
    }
    L({ email: I }), oe(I);
  }, D = async (I) => {
    if (await u.refetchIfValidationError(I)) {
      L({ alert: null });
      return;
    }
    const S = Z.extractServiceErrorCode(I);
    L({
      alert: {
        type: h.danger,
        element: (() => {
          switch (S) {
            case 10130:
              return /* @__PURE__ */ e.createElement(n, { i18nKey: "UpdateUser.error.updateErrorUnderage" }, "You are below the required age");
            default:
              return /* @__PURE__ */ e.createElement(F, { error: I });
          }
        })()
      }
    });
  }, _ = () => {
    L({ alert: null });
  }, oe = (I) => {
    sessionStorage.setItem(De, I), L({
      step: "otherData",
      alert: {
        type: h.success,
        element: /* @__PURE__ */ e.createElement(n, { i18nKey: "ChangeEmailPage.verifyCodeForm.codeSent" }, "A verification code has been sent to your email")
      }
    });
  }, Qe = () => {
    L({ alert: null }), H();
  }, Ve = () => {
    L({ step: "email", email: "" }), ae();
  }, Fe = async ({
    password: I,
    displayName: k,
    username: S,
    reachMinimumAge: ie,
    verificationCode: W,
    acceptedPolicyIds: Ze,
    countryCode: Be,
    dateOfBirth: Ke
  }) => {
    var Le;
    const Je = ((Le = s.user) == null ? void 0 : Le.country) || Be, fe = await p.upgradeHeadlessAccount(
      {
        displayName: k,
        dateOfBirth: Ke,
        password: I,
        username: S,
        country: Je,
        reachMinimumAge: ie,
        emailAddress: t.email,
        code: W
      },
      Ee.IS_DISABLE_USERNAME
    );
    if (fe.error) {
      D(fe.error);
      return;
    }
    await Re(Ze), ae();
    const Ie = await y.refreshToken();
    Ie && P.refreshSession(Ie.access_token, Ie.refresh_token), await P.refreshUser();
  }, ae = () => {
    sessionStorage.removeItem(De);
  }, Ge = (I) => {
    const k = [];
    for (const S of t.displayedPolicies)
      k.push({
        policyId: S.policyId,
        policyVersionId: S.policyVersionId,
        localizedPolicyVersionId: S.localizedPolicyVersionId,
        isAccepted: I.includes(S.policyId)
      });
    return k;
  }, Re = async (I) => {
    const k = s.user, S = Ge(I);
    S && k && await z.bulkAcceptPolicies(S);
  }, We = async () => {
    await P.logout(), ae(), window.location.replace(`/auth${Et.ErrorVerifyAge.link}`);
  }, He = () => {
    const I = new $(j).createLoginURL();
    window.location.replace(I);
  };
  return M ? /* @__PURE__ */ e.createElement("div", { className: Y.headlessAccountPage }, /* @__PURE__ */ e.createElement(Lt, { className: "fixed top-0 right-0 mt-8 mr-8", onChangeLanguage: (I) => T.changeLanguage(I) }), /* @__PURE__ */ e.createElement("div", { className: Y.headlessAccountPageContainer }, /* @__PURE__ */ e.createElement(Ce, null), /* @__PURE__ */ e.createElement("div", { className: Y.headlessAccountPageContainerForm }, /* @__PURE__ */ e.createElement("div", { className: Y.contentWrapper }, /* @__PURE__ */ e.createElement("div", { className: Y.title }, r === "email" && /* @__PURE__ */ e.createElement(n, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.title" }, "Upgrade to Full Account"), r === "otherData" && /* @__PURE__ */ e.createElement(n, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.title" }, "Finish Account Setup")), /* @__PURE__ */ e.createElement("div", { className: Y.description }, r === "email" && /* @__PURE__ */ e.createElement(n, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.description" }, "Enter your email address below to start creating your ", { publisherName: te }, " account"), r === "otherData" && /* @__PURE__ */ e.createElement(n, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.description" }, "Enter the 6-digits verification code we’ve sent to your email at ", /* @__PURE__ */ e.createElement("strong", null, { email: l }), ", and complete the form below"))), /* @__PURE__ */ e.createElement("div", { className: Y.formWrapper }, !!o && /* @__PURE__ */ e.createElement("div", { className: Y.alert }, /* @__PURE__ */ e.createElement(K, { type: o.type, onDismiss: _ }, o.element), !!d.validationsError && /* @__PURE__ */ e.createElement(Q, { className: "btn btn-primary mt-4 w-full", onClick: Qe }, /* @__PURE__ */ e.createElement(n, { i18nKey: "Common.reload" }, "Reload"))), t.step === "email" && /* @__PURE__ */ e.createElement(
    jt,
    {
      styles: Y,
      onRequestVerificationCode: c,
      isRequesting: g.fetchVerificationStatus === b.REQUESTING
    }
  ), t.step === "otherData" && /* @__PURE__ */ e.createElement("div", null, d.validations.length <= 0 && d.validationsFetchStatus === b.FETCHING && /* @__PURE__ */ e.createElement(ge, { className: xe.medium }), d.validations.length > 0 && !d.validationsError && s.user && /* @__PURE__ */ e.createElement(
    At,
    {
      onChangePage: Ve,
      onContinue: Fe,
      onRequestVerificationCode: c,
      policies: i,
      isUpgradingUser: m.upgradeHeadlessAccountFetchStatus === b.FETCHING || E.bulkAcceptPoliciesFetchStatus === b.FETCHING,
      isRequestingVerificationCode: g.fetchVerificationStatus === b.REQUESTING,
      user: s.user,
      styles: Y
    }
  )))), /* @__PURE__ */ e.createElement("div", { className: Y.backContainer }, /* @__PURE__ */ e.createElement("button", { onClick: He }, /* @__PURE__ */ e.createElement(n, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.logout" }, "Back to Login"))), /* @__PURE__ */ e.createElement(pt, null))) : /* @__PURE__ */ e.createElement(ge, null);
};
const ba = () => {
  const [t, a] = U(null), { state: i, mutations: o } = V(), { state: r, mutations: l } = je(), M = G(), s = r.bulkAcceptPoliciesFetchStatus === b.FETCHING, g = !(r.policiesFetchStatus === b.FETCHING) && r.eligibilities && r.eligibilities.length > 0, N = () => {
    const { eligibilities: u } = r;
    return u || [];
  }, m = (u) => {
    a({
      type: h.danger,
      element: /* @__PURE__ */ e.createElement(F, { error: u })
    });
  }, p = async () => {
    const u = N();
    if (u && i.user) {
      const E = me.getAcceptedPolicies(u), z = await l.bulkAcceptPolicies(E);
      if (z.error) {
        m(z.error);
        return;
      }
      const f = await o.refreshToken();
      f && (M.refreshSession(f.access_token, f.refresh_token), await M.refreshUser());
    }
  }, d = () => {
    const u = N();
    return u ? /* @__PURE__ */ e.createElement("ul", { className: "policies" }, u.map((E) => E.policyVersions && E.policyVersions.map((z) => Array.isArray(z.localizedPolicyVersions) ? z.localizedPolicyVersions.map((f) => /* @__PURE__ */ e.createElement("li", { key: f.id, className: "policyItem" }, E.policyName, /* @__PURE__ */ e.createElement(
      "a",
      {
        href: me.createLegalURL(Ct.getLegalUrl(), f.id),
        className: "readMore",
        target: "_blank",
        rel: "noreferrer"
      },
      /* @__PURE__ */ e.createElement(n, { i18nKey: "PromptLegalPage.readMore" }, "Read More")
    ))) : null))) : null;
  };
  return /* @__PURE__ */ e.createElement("div", { className: "promptLegalPage" }, /* @__PURE__ */ e.createElement("div", { className: "promptLegalPageContainer" }, /* @__PURE__ */ e.createElement(Ce, null), /* @__PURE__ */ e.createElement("div", { className: "legalContent" }, r.policiesFetchStatus === b.FETCHING && /* @__PURE__ */ e.createElement(ge, null), (g || s) && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "legalHeader" }, /* @__PURE__ */ e.createElement("h1", null, /* @__PURE__ */ e.createElement(n, { i18nKey: "PromptLegalPage.title" }, "New Agreement and Policy Terms"))), /* @__PURE__ */ e.createElement("div", { className: "legalBody" }, !s && !!t && /* @__PURE__ */ e.createElement(K, { className: "legalBodyAlert", type: t.type, onDismiss: () => a(null) }, t.element), /* @__PURE__ */ e.createElement(n, { i18nKey: "PromptLegalPage.description" }, /* @__PURE__ */ e.createElement("p", null, "We have updated our user agreement and policy to better explain what data we collect from you, why we collect it, and how it's used."), /* @__PURE__ */ e.createElement("p", null, "The following terms have been updated:")), d(), /* @__PURE__ */ e.createElement("div", { className: "notes" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "PromptLegalPage.notes" }, /* @__PURE__ */ e.createElement("p", null, "Please take a moment to read and understand the updated agreement. By clicking the Accept button, you agree to these changes.")))), /* @__PURE__ */ e.createElement("div", { className: "legalFooter" }, /* @__PURE__ */ e.createElement(
    Q,
    {
      loadingIndicator: "SPINNER",
      className: "btn-primary btn-accept",
      isLoading: s,
      disabled: s,
      onClick: p
    },
    /* @__PURE__ */ e.createElement(n, { i18nKey: "PromptLegalPage.accept" }, "Accept")
  ), /* @__PURE__ */ e.createElement(
    Q,
    {
      className: "btn-decline",
      buttonType: lt.TEXT,
      buttonStyle: Mt.NONE,
      onClick: () => M.logout(),
      disabled: s
    },
    /* @__PURE__ */ e.createElement(n, { i18nKey: "PromptLegalPage.decline" }, "Decline")
  ))))));
}, va = "data:image/svg+xml;base64, ", Ua = () => {
  const t = Ee.CONTACT_SUPPORT_EMAIL, a = G(), { state: i } = V(), o = () => {
    a.logout();
  }, r = () => window.location.reload();
  return /* @__PURE__ */ e.createElement("div", { className: "mainPageContainer" }, /* @__PURE__ */ e.createElement("div", { className: "errorPage", style: { backgroundImage: `url(${St})` } }, /* @__PURE__ */ e.createElement("div", { className: "errorPageContentWrapper errorFetchUser" }, /* @__PURE__ */ e.createElement("div", { className: "errorPageContent" }, /* @__PURE__ */ e.createElement("img", { src: va, alt: "space ship alien", loading: "lazy" }), /* @__PURE__ */ e.createElement("div", { className: "errorPageText" }, /* @__PURE__ */ e.createElement("h2", { className: "textHeading" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "FetchUserErrorPage.title" }, "Internal Server Error")), /* @__PURE__ */ e.createElement("div", { className: "textContent" }, !!t && /* @__PURE__ */ e.createElement(n, { i18nKey: "FetchUserErrorPage.textContentWithSupport" }, /* @__PURE__ */ e.createElement("p", null, "Oops.. Something went wrong. Try to refresh this page or log in again. If the problem persists, please contact our support at ", /* @__PURE__ */ e.createElement("a", { href: `mailto:${t}` }, { contactSupportEmail: t }))), !t && /* @__PURE__ */ e.createElement(n, { i18nKey: "FetchUserErrorPage.textContent" }, /* @__PURE__ */ e.createElement("p", null, "Don't worry, our team on Mars is working hard to fix this! For now let's retreat to our home page.")), /* @__PURE__ */ e.createElement("div", { className: "buttonWrapper" }, /* @__PURE__ */ e.createElement(Q, { className: "btn btn-primary", onClick: r }, /* @__PURE__ */ e.createElement(n, { i18nKey: "FetchUserErrorPage.refresh" }, "Refresh")), i.user && /* @__PURE__ */ e.createElement(Q, { className: "btn", onClick: o }, /* @__PURE__ */ e.createElement(n, { i18nKey: "FetchUserErrorPage.logout" }, "Log out")))))))));
};
const Ya = () => /* @__PURE__ */ e.createElement("div", { className: "userInitializationErrorPage" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "UserInitializationErrorPage.unexpectedError" }, "Something went wrong. We're working on getting this fixed as soon as we can.", " ")), Qa = "code is invalid", Va = () => {
  const {
    state: t,
    mutations: { setLocation: a }
  } = B(), { state: i } = ne(), {
    state: { user: o },
    mutations: { fetchCurrentUserInformation: r }
  } = V(), [l] = ee();
  q(() => {
    M();
  }, []);
  const M = async () => {
    var m, p, d;
    const { location: s } = t, g = new URLSearchParams(s.search).get("sso_auth_code"), N = { ...t.location, search: "" };
    if (a(N), o)
      return t.replace(`${(m = t.location) == null ? void 0 : m.pathname}`);
    if (!g)
      return t.replace(i.error.invalidSSOAuthCode.link);
    try {
      const E = await new $(l).exchangeSSOAuthorizationCode({
        code: g
      });
      if (E != null && E.response)
        return await r(), t.replace(`${(p = t.location) == null ? void 0 : p.pathname}`);
    } catch (u) {
      if (Z.isAxiosError(u) && ((d = u == null ? void 0 : u.response) != null && d.status) && (console.error(u), u.response.data.error_description === Qa))
        return t.replace(i.error.invalidSSOAuthCode.link);
    }
  };
  return /* @__PURE__ */ e.createElement("div", { className: "flex h-screen w-full items-center justify-center" }, "Authenticating User. Please Wait...");
}, Qi = ({ children: t }) => {
  var y, g, N;
  const { state: a } = V(), { state: i } = je(), { state: o } = Se(), { state: r } = ne(), {
    state: { location: l }
  } = B();
  if (a.userFetchError && Z.isAxiosError(a.userFetchError)) {
    const m = ((y = a.userFetchError.response) == null ? void 0 : y.status) || -1;
    if (m >= 500)
      return /* @__PURE__ */ e.createElement(Ua, null);
    if (!a.userFetchError.response)
      return /* @__PURE__ */ e.createElement(xt, null);
    if (m !== 401)
      return /* @__PURE__ */ e.createElement(Ya, null);
  }
  return (
    // Exclude link account one time code page,
    // so it will show upgrade headless account page after input email address
    r.linkAccountOneTimeCode.link === l.pathname || // Exclude legal page
    l.pathname.startsWith(r.legal.index.link) ? t : l.search.includes("sso_auth_code") ? /* @__PURE__ */ e.createElement(Va, null) : ue.currentUserIsHeadlessAccount(a.user) ? /* @__PURE__ */ e.createElement(_a, null) : !a.user && ((g = a.mfaData) != null && g.mfaToken) ? /* @__PURE__ */ e.createElement(Rt, null) : me.currentUserIsBlockedByLegal(i.eligibilities) ? /* @__PURE__ */ e.createElement(ba, null) : !(r.accountDeletionSuccess.link === l.pathname) && a.user && ((N = o.gdprDeletionStatus) != null && N.DeletionStatus) ? /* @__PURE__ */ e.createElement(Wt, null) : ue.currentUserNeedsVerification(a.user) ? /* @__PURE__ */ e.createElement(ra, null) : t
  );
};
export {
  Qi as AccountInterceptorsWidget,
  Yi as AuthCodeExchangeWidget
};
