import * as e from "react";
import u from "react";
import { T as r, h as f, i as L, a as C, t as m, j as P, f as g, aX as K, E as b, V as G, X as H, W as q, y as N, L as B, R as z, a1 as S, D as X, p as Y, q as j, g as v, az as O, bc as $, P as J, ao as Q, F as Z, k as M, l as ee, H as te } from "./index-162fd1aa.mjs";
import { L as ne, H as ie } from "./LinkPlatformAccountPage-7c92cd14.mjs";
import { c as _ } from "./reactSlick-cb4a2d39.mjs";
import { O as se } from "./index-eaa2885c.mjs";
import { a as D, T as ae } from "./Tabs-8498653e.mjs";
import { E as oe, U as re } from "./EmailVerificationForm-2518c77a.mjs";
import { a as I } from "./Radio-b897ba55.mjs";
import { W as ce } from "./WarningIcon-c5874dd2.mjs";
import "./dateFns-2367ee5b.mjs";
import "./validator-61879ab7.mjs";
import "./reactPlayer-2f69f369.mjs";
import "react-router-dom";
import "./CommonError-0ae83068.mjs";
import "./starBgGradient-589e5185.mjs";
import "./CommonError-4ed993c7.mjs";
import "./InputPassword-68c495c7.mjs";
import "./Checkbox-5e314906.mjs";
const le = "oneTimeLinkAccountPage _oneTimeLinkAccountPage_bf7da", me = "languageSelector _languageSelector_d5e0f", de = "container _container_a6efe", ue = "pickProgression _pickProgression_2f683", he = "form _form_e2821", pe = "title _title_6c3b6", ge = "description _description_fd39c", Ee = "label _label_9d47e", ke = "input _input_335ab", _e = "resendCode _resendCode_e67ce", fe = "agreementList _agreementList_3f059", Ce = "agreementItem _agreementItem_b7720", Se = "text _text_d4642", Te = "optional _optional_2712e", ye = "sectionTitle _sectionTitle_8d646", Ae = "warningTip _warningTip_e9391", be = "warningIcon _warningIcon_85297", Ne = "accountDetails _accountDetails_6bd2f", Le = "accountDetailsPlatformName _accountDetailsPlatformName_df469", Pe = "accountDetailsEmail _accountDetailsEmail_13afd", ve = "progressionTable _progressionTable_3e79d", we = "noSession _noSession_e12be", xe = "loginIcon _loginIcon_aaba4", Oe = "withSession _withSession_2bd28", Me = "withSessionAvatar _withSessionAvatar_6ab99", De = "withSessionUserName _withSessionUserName_d6c3e", Ie = "withSessionEmail _withSessionEmail_e4cbb", We = "desktop _desktop_2c900", o = {
  oneTimeLinkAccountPage: le,
  languageSelector: me,
  container: de,
  pickProgression: ue,
  form: he,
  title: pe,
  description: ge,
  label: Ee,
  input: ke,
  resendCode: _e,
  agreementList: fe,
  agreementItem: Ce,
  text: Se,
  optional: Te,
  sectionTitle: ye,
  warningTip: Ae,
  warningIcon: be,
  accountDetails: Ne,
  accountDetailsPlatformName: Le,
  accountDetailsEmail: Pe,
  progressionTable: ve,
  noSession: we,
  loginIcon: xe,
  withSession: Oe,
  withSessionAvatar: Me,
  withSessionUserName: De,
  withSessionEmail: Ie,
  desktop: We
}, A = 8, W = 10205, Re = "code is expired";
class Ue extends e.Component {
  constructor(a) {
    super(a), this.onCodeChange = (t) => {
      this.setState({ code: t });
    }, this.dismissAlert = () => {
      this.setState({ alert: null });
    }, this.getDisplayedAlert = (t, n) => n ? /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.oneTimeCodeForm.error.expired" }, "Sorry, the code you entered has expired. Please try again.") : t ? /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.oneTimeCodeForm.error.invalid" }, "Sorry, the code you entered is invalid. Please try again.") : null, this.onSubmit = async () => {
      const t = this.appState.getSdk().IAM.OAuth(), { isSubmitting: n, code: i } = this.state;
      try {
        if (n)
          return;
        this.setState({ isSubmitting: !0 });
        const s = await t.validateOneTimeLinkCode({ oneTimeLinkCode: i });
        if (s.error)
          throw s.error;
        const { valid: l, expired: c } = s.response.data, d = !l;
        if (d || c) {
          this.setState({
            isSubmitting: !1,
            alert: {
              type: f.danger,
              element: this.getDisplayedAlert(d, c)
            }
          });
          return;
        }
        this.props.onContinue(this.state.code);
      } catch (s) {
        console.error(s), this.setState({
          isSubmitting: !1,
          alert: {
            type: f.danger,
            element: /* @__PURE__ */ e.createElement(L, { error: s })
          }
        });
      }
    }, this.state = {
      code: "",
      isSubmitting: !1,
      alert: null
    }, this.appState = C.getAppState();
  }
  render() {
    const { code: a, isSubmitting: t, alert: n } = this.state, i = m("Common.publisherName");
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "text-center" }, /* @__PURE__ */ e.createElement("p", { className: o.title }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.title" }, "Link to an ", { publisherName: i }, " Account")), /* @__PURE__ */ e.createElement("p", { className: o.description }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.oneTimeCodeForm.desc" }, "Enter the code on your device to continue.")), !!n && /* @__PURE__ */ e.createElement(P, { type: n.type, onDismiss: this.dismissAlert, className: "mt-5 text-left" }, n.element)), /* @__PURE__ */ e.createElement(
      se,
      {
        value: a,
        onChange: this.onCodeChange,
        numInputs: A,
        className: "otpInput",
        containerStyle: "otpInputContainer my-5",
        focusStyle: "otpInput__focus",
        shouldAutoFocus: !0,
        isDisabled: t
      }
    ), /* @__PURE__ */ e.createElement(
      g,
      {
        loadingIndicator: "SPINNER",
        className: "btn btn-primary w-full py-2 px-0",
        onClick: this.onSubmit,
        disabled: a.length < A,
        isLoading: t
      },
      m("common.continue")
    ));
  }
}
class F extends e.Component {
  constructor(a) {
    super(a);
  }
  render() {
    const { isUpgradeToFull: a, platformName: t } = this.props, n = m("Common.publisherName");
    return /* @__PURE__ */ e.createElement("div", { className: "text-center" }, /* @__PURE__ */ e.createElement("p", { className: o.title }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.success.title" }, "Success!")), /* @__PURE__ */ e.createElement("p", { className: _(o.description, "mb-4") }, a && /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.success.isUpgrade.desc" }, "You have upgraded to a full ", { publisherName: n }, " account."), !a && /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.success.isLink.desc" }, "Your ", { platformName: t }, " account has been linked with your full ", { publisherName: n }, " account.")), /* @__PURE__ */ e.createElement("p", { className: o.description }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.success.desc2" }, "The screen on your device will refresh shortly. You can close this window.")));
  }
}
class V extends e.Component {
  constructor(a) {
    super(a);
  }
  render() {
    const { onRestart: a } = this.props;
    return /* @__PURE__ */ e.createElement(g, { loadingIndicator: "SPINNER", className: "btn btn-primary mt-6 w-full py-2 px-0", onClick: a }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.restart.button" }, "Input Verification Code"));
  }
}
const w = () => {
  const p = m("Common.publisherName");
  return /* @__PURE__ */ u.createElement("div", { className: "text-center" }, /* @__PURE__ */ u.createElement("p", { className: o.title }, /* @__PURE__ */ u.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.title" }, "Link to an ", { publisherName: p }, " Account")), /* @__PURE__ */ u.createElement("p", { className: o.description }, /* @__PURE__ */ u.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.desc" }, "Link an existing ", { publisherName: p }, " account or upgrade to a full account to save your game progress.")));
};
class Fe extends e.Component {
  constructor(a) {
    super(a), this.fetchPolicies = () => {
      const t = this.appState.getUser();
      t && this.legalManager.fetchPoliciesList(t.country).then(() => {
        const { policiesByCountry: n } = this.legalManager.state;
        this.setState({
          displayedPolicies: K.convertPoliciesToDisplayedPolicies(n || [], b.NAMESPACE)
        });
      }).catch((n) => {
        this.setErrorAlert(n);
      });
    }, this.fetchValidations = async () => {
      this.inputValidationManager.fetchValidations(G()).catch((t) => {
        this.setErrorAlert(t);
      });
    }, this.redirectToOtherData = () => {
      this.setState({
        step: "otherData",
        alert: {
          type: f.success,
          element: m("ChangeEmailPage.verifyCodeForm.codeSent")
        }
      }), this.props.onHideTitle();
    }, this.requestVerificationCode = async (t = this.state.email) => {
      const { step: n, isRequestingVerificationCode: i, alreadyRefreshToken: s } = this.state, { oneTimeLinkCode: l } = this.props, c = n === "email", d = this.appState.getSdk().IAM.OAuth();
      try {
        if (!t || i)
          return;
        if (this.setState({ isRequestingVerificationCode: !0 }), this.verificationManager.setState({ requestVerificationCodeError: null }), c && !s) {
          const h = await d.exchangeTokenByOneTimeLinkCode({ oneTimeLinkCode: l, client_id: b.CLIENT_ID });
          if (h.error)
            throw h.error;
          const { access_token: E, refresh_token: k } = h.response.data;
          this.setState({ alreadyRefreshToken: !0 }), this.appState.refreshSession(E, k);
        }
        await this.verificationManager.sendVerificationCode(t, H.enum.upgradeHeadlessAccount), await this.appState.refreshUser(), c && this.fetchPolicies(), this.setState({ email: t, isRequestingVerificationCode: !1 }, this.redirectToOtherData);
      } catch (h) {
        const { requestVerificationCodeError: E } = this.verificationManager.state;
        if (this.setState({ isRequestingVerificationCode: !1 }), E) {
          this.setErrorAlert(E);
          return;
        }
        console.error(h), this.setErrorAlert(h);
      }
    }, this.setErrorAlert = async (t) => {
      var d;
      if (await this.inputValidationManager.isInputValidationError(t)) {
        q.openValidationOutdatedModal(), this.setState({ alert: null });
        return;
      }
      const { oneTimeLinkCode: n, onHideTitle: i } = this.props, s = N.isAxiosError(t) ? (d = t.response) == null ? void 0 : d.data.error_description : "", l = s == null ? void 0 : s.includes(Re), c = N.extractServiceErrorCode(t);
      if (l) {
        i(), this.setState({
          step: "shouldRestart",
          alert: {
            type: f.danger,
            element: n.length === A ? m("LinkAccountWithOneTimeCodePage.error.expired") : m("LinkAccountWithOneTimeCodePage.error.invalid")
          }
        });
        return;
      }
      this.setState({
        alert: {
          type: f.danger,
          element: (() => {
            switch (c) {
              case 10130:
                return m("UpdateUser.error.updateErrorUnderage");
              default:
                return /* @__PURE__ */ e.createElement(L, { error: t });
            }
          })()
        }
      });
    }, this.dismissAlert = () => {
      this.setState({ alert: null });
    }, this.onReload = () => {
      this.setState({ alert: null }), this.fetchValidations();
    }, this.onGoBackToEmail = () => {
      this.setState({ step: "email", email: "" }), this.props.onShowTitle();
    }, this.onCompleteProcess = async ({
      password: t,
      displayName: n,
      username: i,
      reachMinimumAge: s,
      verificationCode: l,
      acceptedPolicyIds: c
    }) => {
      const { email: d } = this.state, h = this.appState.getUser(), E = (h == null ? void 0 : h.country) || "";
      try {
        await this.linkAccountsManager.upgradeHeadlessAccount(
          {
            displayName: n,
            password: t,
            username: i,
            country: E,
            reachMinimumAge: s,
            emailAddress: d,
            code: l
          },
          b.IS_DISABLE_USERNAME
        ), await this.bulkAcceptPolicies(c);
        const k = await this.appState.userAppManager.refreshToken();
        k && this.appState.refreshSession(k.access_token, k.refresh_token), this.appState.refreshUser(), this.setState({ alert: null, step: "success" });
      } catch (k) {
        this.setErrorAlert(k);
      }
    }, this.getEligibilities = (t) => {
      const n = [], { displayedPolicies: i } = this.state;
      for (const s of i) {
        const { policyId: l, policyVersionId: c, localizedPolicyVersionId: d } = s;
        n.push({
          policyId: l,
          policyVersionId: c,
          localizedPolicyVersionId: d,
          isAccepted: t.includes(s.policyId)
        });
      }
      return n;
    }, this.bulkAcceptPolicies = async (t) => {
      const n = this.appState.getUser(), i = this.getEligibilities(t);
      i && n && await this.legalManager.bulkAcceptPolicies(i);
    }, this.state = {
      email: "",
      alert: null,
      displayedPolicies: [],
      step: "email",
      isRequestingVerificationCode: !1,
      alreadyRefreshToken: !1
    }, this.appState = C.getAppState(), this.verificationManager = this.appState.verificationManager, this.verificationManager.subscribe(() => this.setState({})), this.linkAccountsManager = this.appState.linkAccountManager, this.linkAccountsManager.subscribe(() => this.setState({})), this.legalManager = this.appState.legalAppManager, this.legalManager.subscribe(() => this.setState({})), this.inputValidationManager = this.appState.inputValidationAppManager, this.inputValidationManager.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    this.fetchValidations();
  }
  render() {
    const { displayedPolicies: a, alert: t, step: n, email: i, isRequestingVerificationCode: s } = this.state, { isFetchingUser: l, user: c } = this.appState.getUserManager().state, { isVerifying: d } = this.verificationManager.state, { isUpgradingHeadlessAccount: h } = this.linkAccountsManager.state, { isAccepting: E } = this.legalManager.state, { isFetching: k, fetchError: T, validations: y } = this.inputValidationManager.state, x = n === "shouldRestart";
    return /* @__PURE__ */ e.createElement(e.Fragment, null, n === "otherData" && /* @__PURE__ */ e.createElement("div", { className: "mb-6 text-center" }, /* @__PURE__ */ e.createElement("p", { className: o.title }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.tab.upgradeToFull" }, "Upgrade to Full Account")), /* @__PURE__ */ e.createElement("p", { className: o.description }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.description" }, "Enter the verification code we’ve sent to your email at ", /* @__PURE__ */ e.createElement("strong", null, { email: i }), ", and complete the form below"))), x && /* @__PURE__ */ e.createElement(w, null), !!t && /* @__PURE__ */ e.createElement("div", { className: _("mb-4", x ? "mt-5" : "mt-[-8px]") }, /* @__PURE__ */ e.createElement(P, { type: t.type, onDismiss: this.dismissAlert }, t.element), !!T && /* @__PURE__ */ e.createElement(g, { className: "btn btn-primary mt-4 w-full", onClick: this.onReload }, m("Common.reload"))), n === "email" && /* @__PURE__ */ e.createElement(
      oe,
      {
        styles: o,
        onRequestVerificationCode: this.requestVerificationCode,
        isRequesting: s
      }
    ), n === "otherData" && /* @__PURE__ */ e.createElement(e.Fragment, null, y.length <= 0 && k && /* @__PURE__ */ e.createElement(B, { className: z.medium }), y.length > 0 && !T && c && /* @__PURE__ */ e.createElement(
      re,
      {
        onChangePage: this.onGoBackToEmail,
        onContinue: this.onCompleteProcess,
        onRequestVerificationCode: this.requestVerificationCode,
        policies: a,
        isUpgradingUser: h || E || l,
        inputValidationManager: this.inputValidationManager,
        isRequestingVerificationCode: s,
        user: c,
        email: i,
        isVerifying: d,
        styles: o
      }
    ), /* @__PURE__ */ e.createElement(
      g,
      {
        buttonStyle: S.NONE,
        onClick: this.onGoBackToEmail,
        className: "absolute bottom-0 left-1/2 mb-24 -translate-x-2/4"
      },
      m("common.back")
    )), n === "success" && /* @__PURE__ */ e.createElement(F, { isUpgradeToFull: !0 }), n === "shouldRestart" && /* @__PURE__ */ e.createElement(V, { onRestart: this.props.onRestart }));
  }
}
class Ve extends u.Component {
  constructor(a) {
    super(a);
  }
  render() {
    const { onConfirm: a, onCancel: t, isConfirming: n } = this.props;
    return /* @__PURE__ */ u.createElement(
      X,
      {
        title: /* @__PURE__ */ u.createElement("span", { className: "font-body" }, /* @__PURE__ */ u.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.modal.title" }, "Link an Account")),
        isOpen: !0
      },
      /* @__PURE__ */ u.createElement(Y, null, /* @__PURE__ */ u.createElement("p", { className: "text-sm text-[color:rgb(var(--od-rgb-text),0.65)]" }, /* @__PURE__ */ u.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.modal.message" }, "Are you sure want to continue to link your account?"))),
      /* @__PURE__ */ u.createElement(j, null, /* @__PURE__ */ u.createElement("div", { className: "flex justify-end" }, /* @__PURE__ */ u.createElement(g, { className: "btn btn-ghost mr-2 uppercase", buttonStyle: S.NONE, onClick: t }, m("Common.cancel")), /* @__PURE__ */ u.createElement(g, { className: "btn btn-primary uppercase", isLoading: n, disabled: n, onClick: a }, m("common.yes"))))
    );
  }
}
class R extends e.Component {
  render() {
    const { platformName: a, userName: t, email: n } = this.props;
    return /* @__PURE__ */ e.createElement("div", { className: o.accountDetails }, /* @__PURE__ */ e.createElement("p", { className: o.accountDetailsPlatformName }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.accountDetails.name" }, { platformName: a }, " Account")), /* @__PURE__ */ e.createElement("p", { className: "text-2sm" }, t), /* @__PURE__ */ e.createElement("p", { className: _(o.accountDetailsEmail, !n && "italic") }, n || /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.accountDetails.noEmail" }, "no email registered")));
  }
}
class Ke extends e.Component {
  constructor(a) {
    super(a), this.toggleConfirmDialog = () => {
      this.setState((t) => ({ isConfirmDialogOpen: !t.isConfirmDialogOpen }));
    }, this.chooseGame = (t) => {
      this.setState((n) => {
        const { chosenGames: i } = n;
        return i.set(t, !0), { chosenGames: i };
      });
    }, this.unchooseGame = (t) => {
      this.setState((n) => {
        const { chosenGames: i } = n;
        return i.set(t, !1), { chosenGames: i };
      });
    }, this.onConfirm = async () => {
      const t = this.appState.getSdk().IAM.User(), { isConfirming: n, chosenGames: i } = this.state, { oneTimeLinkCode: s, onError: l, onSuccess: c } = this.props;
      try {
        if (n)
          return;
        this.setState({ isConfirming: !0 });
        const d = await t.linkWithProgression({
          oneTimeLinkCode: s,
          chosenNamespaces: [...i.keys()].filter((h) => i.get(h))
        });
        if (d.error)
          throw d.error;
        this.setState({ isConfirmDialogOpen: !1, isConfirming: !1 }), c();
      } catch (d) {
        this.setState({ isConfirming: !1 }), console.error(d), l(d);
      }
    }, this.onLinkWithAnotherAccount = () => {
      const { createLoginURL: t } = this.appState.getSdk().IAM.UserAuthorization(), { oneTimeLinkCode: n } = this.props, i = v.LinkAccountWithOneTimeCode.makePath(void 0, { oneTimeLinkCode: n }), s = t(i, void 0, n);
      window.location.replace(s);
    }, this.renderAccountDetailsSection = () => {
      const { platformName: t, headlessAccount: n, currentAccount: i } = this.props;
      return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("p", { className: o.sectionTitle }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.accountDetails.title" }, "Account Details")), /* @__PURE__ */ e.createElement("div", { className: "xs:grid-cols-2 mb-6 grid gap-6" }, /* @__PURE__ */ e.createElement(R, { platformName: t, userName: (n == null ? void 0 : n.userName) || (n == null ? void 0 : n.displayName) || "" }), /* @__PURE__ */ e.createElement(
        R,
        {
          platformName: m("Common.companyName"),
          userName: (i == null ? void 0 : i.userName) || (i == null ? void 0 : i.displayName) || "",
          email: (i == null ? void 0 : i.email) || ""
        }
      )), /* @__PURE__ */ e.createElement("hr", null));
    }, this.renderGamesTable = () => {
      const { chosenGames: t } = this.state, { currentAccount: n, headlessAccount: i } = this.props, s = ((i == null ? void 0 : i.linkedGames) || []).concat((n == null ? void 0 : n.linkedGames) || []);
      return /* @__PURE__ */ e.createElement("div", { className: o.progressionTable }, /* @__PURE__ */ e.createElement("table", null, /* @__PURE__ */ e.createElement("thead", null, /* @__PURE__ */ e.createElement("tr", null, /* @__PURE__ */ e.createElement("th", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.table.game" }, "Game")), /* @__PURE__ */ e.createElement("th", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.table.migrate" }, "Migrate to Full Account?")))), /* @__PURE__ */ e.createElement("tbody", null, [...new Set(s)].map((l) => {
        const c = t.get(l);
        return /* @__PURE__ */ e.createElement("tr", { key: l }, /* @__PURE__ */ e.createElement("td", null, l), /* @__PURE__ */ e.createElement("td", { className: "flex items-center" }, /* @__PURE__ */ e.createElement(I, { label: m("common.yes"), className: "mr-6", checked: c, onClick: () => this.chooseGame(l) }), /* @__PURE__ */ e.createElement(I, { label: m("common.no"), checked: c === !1, onClick: () => this.unchooseGame(l) })));
      }))));
    }, this.renderGamesSection = () => {
      const { platformName: t } = this.props, n = m("Common.publisherName");
      return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("p", { className: o.sectionTitle }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.games.title" }, { platformName: t }, " Games")), /* @__PURE__ */ e.createElement("p", { className: _(o.description, "!mt-1 mb-6") }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.games.desc" }, "You have game progression data in your ", { platformName: t }, " account for the following games. For each game, please select whether or not you'd like to migrate your progress to your ", { publisherName: n }, " account.")), /* @__PURE__ */ e.createElement("div", { className: o.warningTip }, /* @__PURE__ */ e.createElement(ce, { defaultColor: !1, className: o.warningIcon }), /* @__PURE__ */ e.createElement("p", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.games.warning" }, "If you choose to migrate your progress, your ", { publisherName: n }, " account progress will be replaced with your", " ", { platformName: t }, " progress for that game."))), this.renderGamesTable(), /* @__PURE__ */ e.createElement("hr", null));
    }, this.renderConfirmButton = () => {
      const { chosenGames: t } = this.state, { currentAccount: n, headlessAccount: i } = this.props, s = [...new Set(((i == null ? void 0 : i.linkedGames) || []).concat((n == null ? void 0 : n.linkedGames) || []))], l = m("Common.publisherName"), c = t.size === s.length;
      return /* @__PURE__ */ e.createElement("div", { className: "text-center" }, /* @__PURE__ */ e.createElement(
        g,
        {
          loadingIndicator: "SPINNER",
          className: "btn btn-primary mx-auto mb-6 w-60 py-2",
          onClick: this.toggleConfirmDialog,
          disabled: !c
        },
        m("Common.confirm")
      ), /* @__PURE__ */ e.createElement("p", { className: o.description }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.linkAnother.question" }, "Don't want to link to this existing account?")), /* @__PURE__ */ e.createElement(g, { className: "text-2sm text-primary-60 mx-auto py-2", buttonStyle: S.NONE, onClick: this.onLinkWithAnotherAccount }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.linkAnother.action" }, "Link with another ", { publisherName: l }, " account")));
    }, this.state = {
      chosenGames: /* @__PURE__ */ new Map(),
      isConfirmDialogOpen: !1,
      isConfirming: !1
    }, this.appState = C.getAppState();
  }
  render() {
    const { isConfirmDialogOpen: a, isConfirming: t } = this.state;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: o.pickProgression }, this.renderAccountDetailsSection(), this.renderGamesSection(), this.renderConfirmButton()), a && /* @__PURE__ */ e.createElement(Ve, { isConfirming: t, onCancel: this.toggleConfirmDialog, onConfirm: this.onConfirm }));
  }
}
class Ge extends e.Component {
  constructor(a) {
    super(a), this.dismissAlert = () => {
      this.setState({ alert: null });
    }, this.onClickLogin = () => {
      const { createLoginURL: t } = this.appState.getSdk().IAM.UserAuthorization(), { oneTimeLinkCode: n } = this.props, i = v.LinkAccountWithOneTimeCode.makePath(void 0, { oneTimeLinkCode: n }), s = t(i, void 0, n);
      window.location.replace(s);
    }, this.setErrorAlert = (t) => {
      const { oneTimeLinkCode: n, onHideTitle: i } = this.props, s = N.extractServiceErrorCode(t);
      s === W && (i(), this.setState({ step: "shouldRestart" })), this.setState({
        alert: {
          type: f.danger,
          element: (() => {
            switch (s) {
              case W:
                return n.length === A ? m("LinkAccountWithOneTimeCodePage.error.expired") : m("LinkAccountWithOneTimeCodePage.error.invalid");
              default:
                return /* @__PURE__ */ e.createElement(L, { error: t });
            }
          })()
        }
      });
    }, this.onLinkToExisting = async () => {
      const t = this.appState.getSdk().IAM.User(), { oneTimeLinkCode: n, onHideTitle: i } = this.props, { isLinking: s } = this.state, l = m("Common.publisherName");
      try {
        if (s)
          return;
        this.setState({ isLinking: !0 });
        const c = await t.getLinkAccountByOneTimeCodeConflict({ oneTimeLinkCode: n });
        if (c.error)
          throw c.error;
        const { platformAlreadyLinked: d, platformLinkConflict: h, platformId: E, currentAccount: k, headlessAccount: T } = c.response.data, y = O.getPlatformName(E);
        if (d || h) {
          this.setState({
            isLinking: !1,
            alert: {
              type: f.danger,
              element: /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.linkToExisting.conflict.message" }, "Unable to link this ", { publisherName: l }, " account. Because it has linked to other ", { platformName: y }, " account previously. Please use another ", { publisherName: l }, " account.")
            }
          });
          return;
        }
        i(), this.setState({ step: "pickProgression", progressionData: { currentAccount: k, headlessAccount: T, platformId: E } });
      } catch (c) {
        console.error(c), this.setState({ isLinking: !1 }), this.setErrorAlert(c);
      }
    }, this.onLinkWithProgressionSuccess = () => {
      this.setState({ alert: null, step: "success" });
    }, this.renderNoSession = () => {
      const t = m("Common.publisherName");
      return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: o.noSession }, /* @__PURE__ */ e.createElement($, { className: o.loginIcon }), /* @__PURE__ */ e.createElement("p", { className: o.description }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.linkToExisting.noSession.message" }, "There is no logged session, please login to your ", { publisherName: t }, " account to continue the account linking process."))), /* @__PURE__ */ e.createElement(g, { className: "btn btn-primary mt-6 w-full py-2 px-0", onClick: this.onClickLogin }, m("Navigation.links.login")));
    }, this.renderWithSession = () => {
      const { userProfile: t, user: n } = this.appState.getUserManager().state, { isLinking: i } = this.state, s = m("Common.publisherName");
      return n ? /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: o.withSession }, /* @__PURE__ */ e.createElement(J, { imageLink: (t == null ? void 0 : t.avatarUrl) || "", className: o.withSessionAvatar }), /* @__PURE__ */ e.createElement("div", { className: "text-2sm ml-4" }, /* @__PURE__ */ e.createElement("p", { className: o.withSessionUserName }, n.userName || n.displayName), /* @__PURE__ */ e.createElement("p", { className: o.withSessionEmail }, n.emailAddress))), /* @__PURE__ */ e.createElement("div", { className: "mt-6 text-center" }, /* @__PURE__ */ e.createElement(g, { className: "btn btn-primary mb-6 w-full py-2 px-0", onClick: this.onLinkToExisting, isLoading: i }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.tab.linkToExisting" }, "Link to Existing Account")), /* @__PURE__ */ e.createElement("p", { className: o.description }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.linkAnother.question" }, "Don't want to link to this existing account?")), /* @__PURE__ */ e.createElement(g, { className: "text-2sm text-primary-60 mx-auto py-2", buttonStyle: S.NONE, onClick: this.onClickLogin }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.linkAnother.action" }, "Link with another ", { publisherName: s }, " account")))) : null;
    }, this.renderLinkAccountStep = () => {
      const { user: t } = this.appState.getUserManager().state;
      return t && !Q.currentUserIsHeadlessAccount(t) ? this.renderWithSession() : this.renderNoSession();
    }, this.state = {
      alert: null,
      isLinking: !1,
      step: "linkAccount",
      progressionData: null
    }, this.appState = C.getAppState();
  }
  render() {
    const { oneTimeLinkCode: a, onRestart: t } = this.props, { alert: n, step: i, progressionData: s } = this.state, l = m("Common.publisherName"), c = O.getPlatformName((s == null ? void 0 : s.platformId) || "");
    return /* @__PURE__ */ e.createElement(e.Fragment, null, i === "pickProgression" && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "mb-5 text-center" }, /* @__PURE__ */ e.createElement("p", { className: o.title }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.title" }, "Choose Game Progression")), /* @__PURE__ */ e.createElement("p", { className: o.description }, /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.pickProgression.desc" }, "Select the game progression you'd like to migrate from your ", { platformName: c }, " account to your ", { publisherName: l }, " ", "account."))), /* @__PURE__ */ e.createElement("hr", null)), i === "shouldRestart" && /* @__PURE__ */ e.createElement(w, null), !!n && /* @__PURE__ */ e.createElement(
      P,
      {
        type: n.type,
        onDismiss: this.dismissAlert,
        className: _("mb-6 text-left", i === "shouldRestart" && "mt-5")
      },
      n.element
    ), i === "linkAccount" && this.renderLinkAccountStep(), i === "pickProgression" && s && /* @__PURE__ */ e.createElement(
      Ke,
      {
        platformName: c,
        oneTimeLinkCode: a,
        currentAccount: s == null ? void 0 : s.currentAccount,
        headlessAccount: s == null ? void 0 : s.headlessAccount,
        onSuccess: this.onLinkWithProgressionSuccess,
        onError: this.setErrorAlert
      }
    ), i === "success" && /* @__PURE__ */ e.createElement(F, { isUpgradeToFull: !1, platformName: c }), i === "shouldRestart" && /* @__PURE__ */ e.createElement(V, { onRestart: t }));
  }
}
const U = ({ isActive: p, onClick: a, label: t }) => /* @__PURE__ */ u.createElement(g, { className: _(D.tab, p && D.active), buttonStyle: S.NONE, onClick: a }, t);
class He extends e.Component {
  constructor(a) {
    super(a), this.showTitleAndTabs = () => {
      this.setState({ areTitleAndTabsHidden: !1 });
    }, this.hideTitleAndTabs = () => {
      this.setState({ areTitleAndTabsHidden: !0 });
    }, this.changeTab = (t) => {
      this.setState({ selectedTab: t });
    }, this.state = {
      areTitleAndTabsHidden: !1,
      selectedTab: "linkToExisting"
    };
  }
  render() {
    const { areTitleAndTabsHidden: a, selectedTab: t } = this.state, { oneTimeLinkCode: n, onRestart: i } = this.props;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, !a && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(w, null), /* @__PURE__ */ e.createElement("div", { className: "my-6" }, /* @__PURE__ */ e.createElement(ae, null, /* @__PURE__ */ e.createElement(
      U,
      {
        isActive: t === "linkToExisting",
        onClick: () => this.changeTab("linkToExisting"),
        label: /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.tab.linkToExisting" }, "Link to Existing Account")
      }
    ), /* @__PURE__ */ e.createElement(
      U,
      {
        isActive: t === "upgradeToFull",
        onClick: () => this.changeTab("upgradeToFull"),
        label: /* @__PURE__ */ e.createElement(r, { i18nKey: "LinkAccountWithOneTimeCodePage.selectLinkMode.tab.upgradeToFull" }, "Upgrade to Full Account")
      }
    )))), t === "upgradeToFull" && /* @__PURE__ */ e.createElement(
      Fe,
      {
        onHideTitle: this.hideTitleAndTabs,
        onShowTitle: this.showTitleAndTabs,
        onRestart: i,
        oneTimeLinkCode: n
      }
    ), t === "linkToExisting" && /* @__PURE__ */ e.createElement(Ge, { onHideTitle: this.hideTitleAndTabs, onRestart: i, oneTimeLinkCode: n }));
  }
}
class ct extends e.Component {
  constructor(a) {
    super(a), this.onRestart = () => {
      this.setState({ step: "oneTimeCode" }), this.appState.state.appHistory.replace(v.LinkAccountWithOneTimeCode.link);
    }, this.goToSelectLinkModeStep = (t) => {
      this.setState({ oneTimeLinkCode: t, step: "selectLinkMode" });
    }, this.renderContent = () => {
      const { step: t, oneTimeLinkCode: n } = this.state;
      switch (t) {
        case "oneTimeCode":
          return /* @__PURE__ */ e.createElement(Ue, { onContinue: this.goToSelectLinkModeStep });
        case "selectLinkMode":
          return /* @__PURE__ */ e.createElement(He, { oneTimeLinkCode: n, onRestart: this.onRestart });
        default:
          return null;
      }
    }, this.state = {
      step: "oneTimeCode",
      oneTimeLinkCode: ""
    }, this.appState = C.getAppState();
  }
  componentDidMount() {
    const { appHistory: a } = this.appState.state, n = Z.getSearchParamsObject(a).get("oneTimeLinkCode");
    n && this.setState({ oneTimeLinkCode: n, step: "selectLinkMode" }), M.updateBackground(`url(${ee})`);
  }
  componentWillUnmount() {
    M.updateBackground(null);
  }
  render() {
    return /* @__PURE__ */ e.createElement("div", { className: _(o.oneTimeLinkAccountPage, { [o.desktop]: te.isDesktopApp() }) }, /* @__PURE__ */ e.createElement(ne, { className: o.languageSelector }), /* @__PURE__ */ e.createElement("div", { className: _(o.container) }, /* @__PURE__ */ e.createElement(ie, null), /* @__PURE__ */ e.createElement("div", { className: o.form }, this.renderContent())));
  }
}
export {
  ct as default
};
