import { FormGroupError as s, FormGroup as l } from "./accelbyte-widgets263.mjs";
import { InputGroup as m } from "./accelbyte-widgets229.mjs";
import { t as p } from "./accelbyte-widgets58.mjs";
import e from "react";
import { Trans as t } from "react-i18next";
import { validateAlphanumeric as u, ValidateAlphaNumericErrorType as c } from "./accelbyte-widgets293.mjs";
import { MAX_SHORT_TEXT_LENGTH as g } from "./accelbyte-widgets339.mjs";
class P extends e.Component {
  constructor(o) {
    super(o), this.refreshComponent = () => this.setState({}), this.onVerificationCodeChange = (r) => {
      const i = r.target.value.toString().toUpperCase(), a = this.state.isPasteVerificationCode ? i.replace(/\s/g, "") : i;
      this.props.validation.set("verificationCode", u(a)), this.props.onChangeVerificationCode(a), this.setState({ isPasteVerificationCode: !1 });
    }, this.onPasteVerificationCode = () => {
      this.setState({ isPasteVerificationCode: !0 });
    }, this.renderVerificationCodeError = (r) => {
      if (!r)
        return null;
      switch (r) {
        case c.enum.empty:
          return /* @__PURE__ */ e.createElement(s, null, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verifyCodeError.empty" }, "You must enter your verification code"));
        case c.enum.exceedLengthLimit:
          return /* @__PURE__ */ e.createElement(s, null, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verifyCodeError.ExceedLimit" }, "Verification code must not exceed ", { MAX_SHORT_TEXT_LENGTH: g }, " characters"));
        case c.enum.invalidFormat:
          return /* @__PURE__ */ e.createElement(s, null, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verifyCodeError.invalidFormat" }, "Please enter a valid verification code"));
        default:
          return /* @__PURE__ */ e.createElement(t, { 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: o, onRequestVerificationCode: r, verificationCode: i, onChangePage: a, validation: d, styles: n } = this.props;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(l, { className: n.formGroup }, /* @__PURE__ */ e.createElement("div", { className: n.label }, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.verificationCode" }, "Verification Code")), /* @__PURE__ */ e.createElement(
      m,
      {
        type: "text",
        value: i || "",
        className: n.input,
        placeholder: p("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.placeholder.verificationCodePlaceholder"),
        onChange: this.onVerificationCodeChange,
        onPaste: this.onPasteVerificationCode
      }
    ), this.renderVerificationCodeError(d.get("verificationCode")), /* @__PURE__ */ e.createElement("div", { className: n.resendCode }, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.didntReceiveEmail" }, "Didn't receive the email?"), o && /* @__PURE__ */ e.createElement("span", null, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.requestingCode" }, " Requesting...")), !o && /* @__PURE__ */ e.createElement("span", { onClick: () => r && r() }, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.resend" }, "Click here to resend"))), /* @__PURE__ */ e.createElement("div", { className: n.resendCode }, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.enterWrongEmail" }, "Entered the wrong email? "), /* @__PURE__ */ e.createElement("span", { onClick: () => a && a() }, /* @__PURE__ */ e.createElement(t, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountForm.clickToChange" }, "Click here to change")))));
  }
}
export {
  P as UpgradeHeadlessVerification
};
