import { V as c, h as n, T as r, W as p, i as d, U as h, H as m, X as g, a as u, k as o, l as f, g as S, Y as E } from "./index-162fd1aa.mjs";
import { B as C } from "./BackLinkIcon-de8f5572.mjs";
import e from "react";
import { Link as V } from "react-router-dom";
import "./dateFns-2367ee5b.mjs";
import "./validator-61879ab7.mjs";
import "./reactPlayer-2f69f369.mjs";
import "./reactSlick-cb4a2d39.mjs";
class N extends e.Component {
  constructor(a) {
    super(a), this.getInputValidations = () => {
      this.inputValidationManager.fetchValidations(c()).then(() => {
        const { fetchError: t } = this.inputValidationManager.state;
        t && this.setErrorAlert(t);
      });
    }, this.dismissAlert = () => {
      this.setState({ alert: null });
    }, this.setSentSuccessAlert = () => {
      this.setState({
        alert: {
          type: n.success,
          element: /* @__PURE__ */ e.createElement(r, { i18nKey: "ChangeEmailPage.verifyCodeForm.codeSent" }, "A verification code has been sent to your email")
        }
      });
    }, this.setErrorAlert = async (t) => {
      if (await this.inputValidationManager.isInputValidationError(t)) {
        p.openValidationOutdatedModal(), this.setState({ alert: null });
        return;
      }
      this.setState({
        alert: {
          type: n.danger,
          element: /* @__PURE__ */ e.createElement(d, { error: t })
        }
      });
    }, this.notifyFirstVerificationCodeSent = () => {
      const { location: t } = this.appState.state.appHistory;
      h.silentSearchParamsBuilder(t.search).has("codeSent") && (this.setSentSuccessAlert(), this.appState.state.appHistory.replace(t.pathname));
    }, this.notifyVerificationCodeSent = () => {
      this.setSentSuccessAlert();
    }, this.onStepChanged = () => this.setState({ alert: null }), this.updateEmailAndRedirectToVerifyPage = async (t, i) => {
      const { appHistory: s } = this.appState.state;
      this.setState({ isUpdating: !0 });
      try {
        await this.userAppManager.updateEmail(t, i), m.isDesktopApp() ? (await this.appState.refreshUser(), s.replace(s.location.pathname)) : await this.appState.fetchAllUserInformation();
      } catch (l) {
        this.setErrorAlert(l);
      } finally {
        this.setState({ isUpdating: !1 });
      }
    }, this.sendVerificationCode = async () => {
      const t = this.appState.getUser();
      this.verificationManager.sendVerificationCode((t == null ? void 0 : t.emailAddress) || "", g.enum.UpdateEmailAddress).then(() => {
        this.notifyVerificationCodeSent();
      }).catch((i) => {
        this.setErrorAlert(i);
      });
    }, this.state = {
      alert: null,
      step: "verifyCode",
      isUpdating: !1
    }, this.appState = u.getAppState(), this.userAppManager = this.appState.getUserManager(), this.verificationManager = this.appState.verificationManager, this.verificationManager.subscribe(() => this.setState({})), this.inputValidationManager = this.appState.inputValidationAppManager, this.inputValidationManager.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    o.updateBackground(`url(${f})`), this.getInputValidations(), this.notifyFirstVerificationCodeSent();
  }
  componentWillUnmount() {
    o.updateBackground(null);
  }
  render() {
    const a = this.appState.getUser(), { isRequestingVerificationCode: t, isVerifying: i } = this.verificationManager.state;
    return /* @__PURE__ */ e.createElement("div", { className: "changeEmailPage" }, /* @__PURE__ */ e.createElement("div", { className: "changeEmailPageContainer" }, /* @__PURE__ */ e.createElement("main", null, /* @__PURE__ */ e.createElement("div", { className: "navigationContainer" }, /* @__PURE__ */ e.createElement(V, { to: S.Profile.makePath(), className: "btnBack" }, /* @__PURE__ */ e.createElement(C, null), /* @__PURE__ */ e.createElement("p", { className: "backText" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "Navigation.editHistory.backlink" }, "Back to Profile")))), /* @__PURE__ */ e.createElement("div", { className: "changeEmailSubPage" }, /* @__PURE__ */ e.createElement(
      E,
      {
        email: a && a.emailAddress || "",
        isRequestingCode: t,
        isVerifying: i,
        onResendCode: this.sendVerificationCode,
        onUpdateEmail: this.updateEmailAndRedirectToVerifyPage,
        alert: this.state.alert,
        onDismissAlert: this.dismissAlert,
        oldEmail: a && a.emailAddress || "",
        isUpdatingEmail: this.state.isUpdating,
        inputValidationManager: this.inputValidationManager
      }
    )))));
  }
}
export {
  N as default
};
