import e from "react";
import { Trans as r } from "react-i18next";
import { Button as m } from "./accelbyte-widgets107.mjs";
import { FormGroupError as d, FormGroup as c } from "./accelbyte-widgets263.mjs";
import { InputGroup as p } from "./accelbyte-widgets229.mjs";
import { PasswordConstraint as u } from "./accelbyte-widgets265.mjs";
import { t as g } from "./accelbyte-widgets58.mjs";
import { InputValidationHelper as s, ValidateableInputField as l } from "@accelbyte/sdk-iam";
import { Ctx as E } from "./accelbyte-widgets33.mjs";
import { Validation as h } from "./accelbyte-widgets269.mjs";
import { ValidateEmailErrorType as o } from "./accelbyte-widgets340.mjs";
import { CommonValidationErrorType as f } from "./accelbyte-widgets341.mjs";
class F extends e.Component {
  constructor(n) {
    super(n), this.onEmailChange = (a) => {
      const t = a.target.value.toString().toLocaleLowerCase(), { validations: i } = this.inputValidationManager.state;
      this.validation.set("email", s.validateEmail(t, i)), this.setState({ email: t });
    }, this.onFormSubmit = (a) => {
      const { onRequestVerificationCode: t } = this.props;
      a.preventDefault();
      const { email: i } = this.state;
      !this.validation.get("email") && i && t(i);
    }, this.state = {
      email: ""
    }, this.appState = E.getAppState(), this.inputValidationManager = this.appState.inputValidationAppManager, this.inputValidationManager.subscribe(() => this.setState({})), this.validation = new h(), this.validation.listen(() => this.setState({}));
  }
  renderEmailError(n) {
    if (!n)
      return null;
    const { validations: a } = this.inputValidationManager.state, t = s.getValidationByKey(l.enum.email, a), i = {
      [o.enum.empty]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.empty" }, "You must enter a new email address"),
      [o.enum.lessThanLengthLimit]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.lessThanLengthLimit" }, "Email must not less than ", { MIN_EMAIL_LENGTH: t == null ? void 0 : t.minLength }, " characters"),
      [o.enum.exceedLengthLimit]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.ExceedLimit" }, "Email must not exceed ", { MAX_EMAIL_LENGTH: t == null ? void 0 : t.maxLength }, " characters"),
      [o.enum.invalidFormat]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.InvalidFormat" }, "Please provide a valid Email format"),
      [f.enum.containsForbiddenWords]: /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.emailError.containsForbiddenWords" }, "Email contains prohibited word or use blocked domain")
    };
    return /* @__PURE__ */ e.createElement(d, null, i[n]);
  }
  render() {
    const { email: n } = this.state, { styles: a, isRequesting: t } = this.props, { validations: i } = this.inputValidationManager.state;
    return /* @__PURE__ */ e.createElement("form", { onSubmit: this.onFormSubmit, noValidate: !0 }, /* @__PURE__ */ e.createElement(c, null, /* @__PURE__ */ e.createElement("div", { className: a.label }, /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.email" }, "Email")), /* @__PURE__ */ e.createElement(
      p,
      {
        type: "email",
        className: a.input,
        value: n,
        placeholder: g("UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.placeholder.email"),
        onChange: this.onEmailChange,
        popoverContent: /* @__PURE__ */ e.createElement(
          u,
          {
            descriptions: s.getValidationDescription(l.enum.email, i)
          }
        )
      }
    ), this.renderEmailError(this.validation.get("email"))), /* @__PURE__ */ e.createElement(
      m,
      {
        loadingIndicator: "SPINNER",
        disabled: !!this.validation.get("email") || !n,
        className: "btn btn-primary w-full uppercase",
        type: "submit",
        isLoading: t
      },
      /* @__PURE__ */ e.createElement(r, { i18nKey: "UpgradeHeadlessAccountPage.UpgradeHeadlessAccountPage.continue" }, "CONTINUE")
    ));
  }
}
export {
  F as EmailVerificationForm
};
