import { aB as W, T as r, aC as L, aD as c, b2 as X, aF as A, $ as f, t as s, E as S, aH as m, aW as H, aV as h, aX as F, b3 as b, a as x, aE as w, aJ as E, aI as C, f as D, b1 as v, aR as Y } from "./index-162fd1aa.mjs";
import { C as M } from "./Checkbox-5e314906.mjs";
import { I as $ } from "./InputPassword-68c495c7.mjs";
import e from "react";
class J extends e.Component {
  constructor(i) {
    super(i), this.refreshComponent = () => this.setState({}), this.onVerificationCodeChange = (t) => {
      const a = t.target.value.toString().toUpperCase(), n = this.state.isPasteVerificationCode ? a.replace(/\s/g, "") : a;
      this.props.validation.set("verificationCode", W(n)), this.props.onChangeVerificationCode(n), this.setState({ isPasteVerificationCode: !1 });
    }, this.onPasteVerificationCode = () => {
      this.setState({ isPasteVerificationCode: !0 });
    }, this.renderVerificationCodeError = (t) => {
      if (!t)
        return null;
      switch (t) {
        case L.empty:
          return /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verifyCodeError.empty" }, "You must enter your verification code"));
        case L.exceedLengthLimit:
          return /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verifyCodeError.ExceedLimit" }, "Verification code must not exceed ", { MAX_SHORT_TEXT_LENGTH: X }, " characters"));
        case L.invalidFormat:
          return /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verifyCodeError.invalidFormat" }, "Please enter a valid verification code"));
        default:
          return /* @__PURE__ */ e.createElement(r, { i18nKey: "CommonError.unknownError" }, "Something went wrong. Please contact support for assistance.");
      }
    }, this.state = {
      isPasteVerificationCode: !1
    };
  }
  componentDidMount() {
    this.props.validation.listen(this.refreshComponent);
  }
  componentWillUnmount() {
    this.props.validation.unlisten(this.refreshComponent);
  }
  render() {
    const { isRequestingVerificationCode: i, onRequestVerificationCode: t, verificationCode: a, onChangePage: n, validation: l, styles: o } = this.props;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(A, { className: o.formGroup }, /* @__PURE__ */ e.createElement("div", { className: o.label }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verificationCode" }, "Verification Code")), /* @__PURE__ */ e.createElement(
      f,
      {
        type: "text",
        value: a || "",
        className: o.input,
        placeholder: s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.placeholder.verificationCodePlaceholder"),
        onChange: this.onVerificationCodeChange,
        onPaste: this.onPasteVerificationCode
      }
    ), this.renderVerificationCodeError(l.get("verificationCode")), /* @__PURE__ */ e.createElement("div", { className: o.resendCode }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.didntReceiveEmail" }, "Didn't receive the email?"), i && /* @__PURE__ */ e.createElement("span", null, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.requestingCode" }, " Requesting...")), !i && /* @__PURE__ */ e.createElement("span", { onClick: () => t && t() }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.resend" }, "Click here to resend"))), /* @__PURE__ */ e.createElement("div", { className: o.resendCode }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.enterWrongEmail" }, "Entered the wrong email? "), /* @__PURE__ */ e.createElement("span", { onClick: () => n && n() }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.clickToChange" }, "Click here to change")))));
  }
}
class ee extends e.Component {
  constructor(i) {
    super(i), this.updatePolicies = () => {
      const { policies: t } = this.props;
      t && this.setState({
        requiredPolicies: t.filter((a) => a.isMandatory),
        optionalPolicies: t.filter((a) => !a.isMandatory)
      });
    }, this.isDisplayNameDisabled = () => S.IS_DISABLE_DISPLAY_NAME, this.isUserNameDisabled = () => S.IS_DISABLE_USERNAME, this.onChangeDisplayName = (t) => {
      const a = t.target.value, { validations: n } = this.props.inputValidationManager.state;
      this.validation.set("displayName", m.validateDisplayName(a, this.isUserNameDisabled(), n)), this.setState({ displayName: a });
    }, this.onChangeUsername = (t) => {
      const a = t.target.value, { validations: n } = this.props.inputValidationManager.state;
      this.validation.set("username", m.validateUserName(a, n)), this.setState({ username: a });
    }, this.onPasswordChange = (t) => {
      const a = t.target.value, { validations: n } = this.props.inputValidationManager.state;
      this.validation.set("password", m.validatePassword(a, n)), this.setState({
        password: a
      });
    }, this.onVerificationCodeChange = (t) => {
      this.setState({ verificationCode: t });
    }, this.renderPasswordError = ({ min: t, max: a } = {}) => {
      const n = this.validation.get("password");
      if (!n)
        return null;
      switch (n) {
        case h.empty:
          return /* @__PURE__ */ e.createElement(c, null, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.form.passwordEmptyError"));
        case h.lessThanLengthLimit:
          return /* @__PURE__ */ e.createElement(c, null, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.form.passwordLessThanLengthLimit", { PASSWORD_MIN_LIMIT: t }));
        case h.exceedLengthLimit:
          return /* @__PURE__ */ e.createElement(c, null, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.form.passwordExceedLimit", { PASSWORD_MAX_LENGTH: a }));
        case H.invalidFormat:
          return /* @__PURE__ */ e.createElement(c, null, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.form.passwordInvalidFormat"));
        default:
          return s("CommonError.unknownError");
      }
    }, this.renderMinimumAgeCheckbox = () => {
      const { reachMinimumAge: t } = this.state, { age: a } = this.userManager.state.ageRestriction, { styles: n } = this.props;
      if (a)
        return /* @__PURE__ */ e.createElement("div", { className: n.agreementList }, /* @__PURE__ */ e.createElement("div", { className: n.agreementItem }, /* @__PURE__ */ e.createElement(
          M,
          {
            isChecked: t,
            onChange: () => {
              this.setState({ reachMinimumAge: !t });
            }
          }
        ), /* @__PURE__ */ e.createElement("div", { className: n.text }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.minimumAge" }, "I confirm that I am ", { age: a }, " years of age or older."))));
    }, this.renderRequiredPolicies = () => {
      const { requiredPolicies: t, isRequiredPolicyAccepted: a } = this.state, { styles: n } = this.props;
      if (t.length)
        return /* @__PURE__ */ e.createElement("div", { className: n.agreementList }, /* @__PURE__ */ e.createElement("div", { className: n.agreementItem }, /* @__PURE__ */ e.createElement(
          M,
          {
            isChecked: a,
            onChange: () => {
              this.setState({ isRequiredPolicyAccepted: !a });
            }
          }
        ), /* @__PURE__ */ e.createElement("div", { className: n.text }, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.tos.haveRead"), t.map((l, o) => {
          const d = F.createLegalURL(b.getLegalUrl(), l.localizedPolicyVersionId);
          return /* @__PURE__ */ e.createElement(e.Fragment, null, o === t.length - 1 && t.length > 1 && s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.tos.and"), /* @__PURE__ */ e.createElement("span", { key: o }, /* @__PURE__ */ e.createElement("a", { href: d, target: "_blank", rel: "noreferrer" }, l.policyName)), t.length !== 1 && o !== t.length - 1 && o !== t.length - 2 ? ", " : " ");
        }))));
    }, this.renderOptionalPolicies = () => {
      const { optionalPolicies: t, acceptedOptionalPolicyIdMap: a } = this.state, { styles: n } = this.props;
      return !t || !t.length ? null : t.map((l) => {
        const o = F.createLegalURL(b.getLegalUrl(), l.localizedPolicyVersionId);
        return /* @__PURE__ */ e.createElement("div", { className: n.agreementList, key: l.policyId }, /* @__PURE__ */ e.createElement("div", { className: n.agreementItem }, /* @__PURE__ */ e.createElement(
          M,
          {
            isChecked: a.get(l.policyId),
            onChange: () => {
              this.onClickOptionalPolicyCheckbox(l);
            }
          }
        ), /* @__PURE__ */ e.createElement("span", { className: `${n.text} ${n.optional}` }, /* @__PURE__ */ e.createElement(r, { i18nKey: "linkPlatformAccountPage.LinkNewAccount.optional" }, "[Optional]")), /* @__PURE__ */ e.createElement("div", { className: n.text }, l.policyName, /* @__PURE__ */ e.createElement("a", { href: o, target: "_blank", rel: "noreferrer" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.learnMore" }, "Learn more.")))));
      });
    }, this.onClickOptionalPolicyCheckbox = (t) => {
      const { acceptedOptionalPolicyIdMap: a } = this.state;
      a.set(t.policyId, !a.get(t.policyId)), this.setState({ acceptedOptionalPolicyIdMap: a });
    }, this.onClickContinue = () => {
      const { isRequiredPolicyAccepted: t, requiredPolicies: a, acceptedOptionalPolicyIdMap: n } = this.state, l = [];
      if (t)
        for (const o of a)
          l.push(o.policyId);
      n.forEach((o, d) => {
        o && l.push(d);
      }), this.props.onContinue({
        ...this.state,
        acceptedPolicyIds: l,
        reachMinimumAge: !0
      });
    }, this.state = {
      verificationCode: "",
      displayName: "",
      username: "",
      password: "",
      requiredPolicies: [],
      optionalPolicies: [],
      isRequiredPolicyAccepted: !1,
      reachMinimumAge: !1,
      acceptedOptionalPolicyIdMap: /* @__PURE__ */ new Map()
    }, this.userManager = x.getAppState().userAppManager, this.validation = new w(), this.validation.listen(() => this.setState({}));
  }
  componentDidMount() {
    const { country: i } = this.props.user;
    this.userManager.getAgeRestrictionByCountry(i), this.updatePolicies();
  }
  componentDidUpdate(i) {
    const { policies: t } = this.props;
    JSON.stringify(t) !== JSON.stringify(i.policies) && this.updatePolicies();
  }
  renderDisplayNameError(i, t = {}) {
    if (!i)
      return null;
    switch (i) {
      case h.empty:
        return /* @__PURE__ */ e.createElement(c, null, s("AccountMyProfilePage.form.displayNameEmptyError"));
      case h.lessThanLengthLimit:
        return /* @__PURE__ */ e.createElement(c, null, s("AccountMyProfilePage.form.lessThanLengthLimit", { DISPLAY_NAME_MIN_LIMIT: t.min }));
      case h.exceedLengthLimit:
        return /* @__PURE__ */ e.createElement(c, null, s("AccountMyProfilePage.form.displayNameExceedLimit", { MAX_DISPLAY_NAME_LENGTH: t.max }));
      case H.invalidFormat:
        return /* @__PURE__ */ e.createElement(c, null, s("AccountMyProfilePage.form.displayNameInvalidFormat"));
      default:
        return s("CommonError.unknownError");
    }
  }
  renderUserNameError(i, t = {}) {
    if (!i)
      return null;
    switch (i) {
      case h.empty:
        return /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountMyProfilePage.form.userName.emptyError" }, "The username cannot be empty"));
      case h.lessThanLengthLimit:
        return /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountMyProfilePage.form.userName.lessThanLengthLimit" }, "Your username must contain at least ", { MIN_USERNAME_LENGTH: t.min }, " characters"));
      case h.exceedLengthLimit:
        return /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountMyProfilePage.form.userName.exceedLimit" }, "Your username must not exceed ", { MAX_USERNAME_LENGTH: t.max }, " characters"));
      case H.invalidFormat:
        return /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountMyProfilePage.form.userName.invalidFormat" }, "Please enter a valid username format"));
      default:
        return /* @__PURE__ */ e.createElement(r, { i18nKey: "CommonError.unknownError" }, "Something went wrong. Please contact administrator.");
    }
  }
  render() {
    const { user: i, onChangePage: t, inputValidationManager: a, onRequestVerificationCode: n, isRequestingVerificationCode: l, isUpgradingUser: o, styles: d } = this.props, { validations: y } = a.state, { displayName: U, username: N, password: P, requiredPolicies: R, isRequiredPolicyAccepted: _, reachMinimumAge: k, verificationCode: I } = this.state, { countryName: K, age: T } = this.userManager.state.ageRestriction, u = m.getValidationByKey(E.enum.username, y), g = m.getValidationByKey(E.enum.displayName, y), p = m.getValidationByKey(E.enum.password, y), q = this.isUserNameDisabled() ? U.length > 0 : !0, O = this.isUserNameDisabled() || N.length > 0, G = I.length > 0, B = this.validation.isAllValid() && (_ || R.length === 0) && (k || !T) && P.length > 0 && q && O && G;
    if (i)
      return /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(
        J,
        {
          verificationCode: I,
          onChangePage: t,
          isRequestingVerificationCode: l,
          onRequestVerificationCode: n,
          onChangeVerificationCode: this.onVerificationCodeChange,
          validation: this.validation,
          styles: d
        }
      ), /* @__PURE__ */ e.createElement("hr", null), /* @__PURE__ */ e.createElement(A, null, /* @__PURE__ */ e.createElement("div", { className: d.label }, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.country")), /* @__PURE__ */ e.createElement(f, { type: "text", value: K || i.country, disabled: !0, className: d.input })), !this.isUserNameDisabled() && /* @__PURE__ */ e.createElement(A, null, /* @__PURE__ */ e.createElement("div", { className: d.label }, /* @__PURE__ */ e.createElement("div", null, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.userName")), /* @__PURE__ */ e.createElement("div", null, N.length, "/", u == null ? void 0 : u.maxLength)), /* @__PURE__ */ e.createElement(
        f,
        {
          className: d.input,
          value: N,
          onChange: this.onChangeUsername,
          placeholder: s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.placeholder.userName"),
          disabled: !!this.props.inputValidationManager.state.fetchError,
          popoverContent: /* @__PURE__ */ e.createElement(
            C,
            {
              descriptions: m.getValidationDescription(E.enum.username, y)
            }
          ),
          maxLength: u == null ? void 0 : u.maxLength
        }
      ), this.renderUserNameError(this.validation.get("username"), {
        min: u && u.minLength,
        max: u && u.maxLength
      })), !this.isDisplayNameDisabled() && /* @__PURE__ */ e.createElement(A, null, /* @__PURE__ */ e.createElement("div", { className: d.label }, /* @__PURE__ */ e.createElement("div", null, `${s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.displayName")} ${s(
        "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.tos.optional"
      )}`), /* @__PURE__ */ e.createElement("div", null, U.length, "/", g == null ? void 0 : g.maxLength)), /* @__PURE__ */ e.createElement(
        f,
        {
          className: d.input,
          value: U,
          onChange: this.onChangeDisplayName,
          placeholder: s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.placeholder.displayName"),
          popoverContent: /* @__PURE__ */ e.createElement(
            C,
            {
              descriptions: m.getValidationDescription(E.enum.displayName, y)
            }
          ),
          maxLength: g == null ? void 0 : g.maxLength
        }
      ), this.renderDisplayNameError(this.validation.get("displayName"), {
        min: g && g.minLength,
        max: g && g.maxLength
      })), /* @__PURE__ */ e.createElement(A, null, /* @__PURE__ */ e.createElement("div", { className: d.label }, /* @__PURE__ */ e.createElement("div", null, s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.password")), /* @__PURE__ */ e.createElement("div", null, P.length, "/", p == null ? void 0 : p.maxLength)), /* @__PURE__ */ e.createElement(
        $,
        {
          className: d.input,
          value: P,
          placeholder: s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.placeholder.password"),
          togglePassword: !0,
          onChange: this.onPasswordChange,
          popoverContent: /* @__PURE__ */ e.createElement(
            C,
            {
              descriptions: m.getValidationDescription(E.enum.password, y)
            }
          ),
          maxLength: p == null ? void 0 : p.maxLength,
          hasStrengthMeter: !this.validation.get("password") && !!P
        }
      ), this.renderPasswordError({
        min: p && p.minLength,
        max: p && p.maxLength
      })), /* @__PURE__ */ e.createElement(A, null, this.renderMinimumAgeCheckbox(), this.renderRequiredPolicies(), this.renderOptionalPolicies()), /* @__PURE__ */ e.createElement(
        D,
        {
          loadingIndicator: "SPINNER",
          className: "btn btn-primary w-full uppercase",
          onClick: () => this.onClickContinue(),
          disabled: !B || o,
          isLoading: o
        },
        s("common.complete")
      ));
  }
}
class te extends e.Component {
  constructor(i) {
    super(i), this.onEmailChange = (t) => {
      const a = t.target.value.toString().toLocaleLowerCase(), { validations: n } = this.inputValidationManager.state;
      this.validation.set("email", m.validateEmail(a, n)), this.setState({ email: a });
    }, this.onFormSubmit = (t) => {
      const { onRequestVerificationCode: a } = this.props;
      t.preventDefault();
      const { email: n } = this.state;
      !this.validation.get("email") && n && a(n);
    }, this.state = {
      email: ""
    }, this.appState = x.getAppState(), this.inputValidationManager = this.appState.inputValidationAppManager, this.inputValidationManager.subscribe(() => this.setState({})), this.validation = new w(), this.validation.listen(() => this.setState({}));
  }
  renderEmailError(i) {
    if (!i)
      return null;
    const { validations: t } = this.inputValidationManager.state, a = m.getValidationByKey(E.enum.email, t), n = {
      [v.empty]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.empty" }, "You must enter a new email address"),
      [v.lessThanLengthLimit]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.lessThanLengthLimit" }, "Email must not less than ", { MIN_EMAIL_LENGTH: a == null ? void 0 : a.minLength }, " characters"),
      [v.exceedLengthLimit]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.ExceedLimit" }, "Email must not exceed ", { MAX_EMAIL_LENGTH: a == null ? void 0 : a.maxLength }, " characters"),
      [v.invalidFormat]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.InvalidFormat" }, "Please provide a valid Email format"),
      [Y.containsForbiddenWords]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.containsForbiddenWords" }, "Email contains prohibited word or use blocked domain")
    };
    return /* @__PURE__ */ e.createElement(c, null, n[i]);
  }
  render() {
    const { email: i } = this.state, { styles: t, isRequesting: a } = this.props, { validations: n } = this.inputValidationManager.state;
    return /* @__PURE__ */ e.createElement("form", { onSubmit: this.onFormSubmit, noValidate: !0 }, /* @__PURE__ */ e.createElement(A, null, /* @__PURE__ */ e.createElement("div", { className: t.label }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.email" }, "Email")), /* @__PURE__ */ e.createElement(
      f,
      {
        type: "email",
        className: t.input,
        value: i,
        placeholder: s("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.placeholder.email"),
        onChange: this.onEmailChange,
        popoverContent: /* @__PURE__ */ e.createElement(
          C,
          {
            descriptions: m.getValidationDescription(E.enum.email, n)
          }
        )
      }
    ), this.renderEmailError(this.validation.get("email"))), /* @__PURE__ */ e.createElement(
      D,
      {
        loadingIndicator: "SPINNER",
        disabled: !!this.validation.get("email") || !i,
        className: "btn btn-primary w-full uppercase",
        type: "submit",
        isLoading: a
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.continue" }, "CONTINUE")
    ));
  }
}
export {
  te as E,
  ee as U
};
