import { b6 as h, bb as E, f as y, m as g, Q as v, N as _, V as k, h as P, i as U, t, j as S, K as b, T as N, a as x, k as u, l as T, b9 as C } from "./index-162fd1aa.mjs";
import e from "react";
import "./dateFns-2367ee5b.mjs";
import "./validator-61879ab7.mjs";
import "./reactPlayer-2f69f369.mjs";
import "react-router-dom";
import "./reactSlick-cb4a2d39.mjs";
class o extends e.Component {
  constructor(i) {
    super(i);
  }
  render() {
    const { isSuccess: i, onClickButton: r, title: s, description: a, buttonText: n, buttonDataQa: d = null, titleDataQa: c = null, isLoading: p } = this.props;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("div", { className: "flex justify-center" }, i ? /* @__PURE__ */ e.createElement(h, { checked: !0, fill: !0 }) : /* @__PURE__ */ e.createElement(E, { className: "dangerIcon" })), /* @__PURE__ */ e.createElement("div", { className: "mb-4 text-center" }, /* @__PURE__ */ e.createElement("p", { className: "messageTitle my-4", "data-qa-id": c }, s), /* @__PURE__ */ e.createElement("p", { className: "messageDesc" }, a)), /* @__PURE__ */ e.createElement(
      y,
      {
        loadingIndicator: "SPINNER",
        className: "btn btn-primary w-full",
        onClick: r,
        "data-qa-id": d,
        isLoading: p
      },
      n
    ));
  }
}
const l = g.enum([
  "failed_to_verify_invalid_link",
  "failed_to_verify_server_error",
  "failed_to_verify_user_not_found",
  "failed_to_verify_expired_link"
]), m = g.enum(["message", "checkEmail"]);
class D extends e.Component {
  constructor(i) {
    super(i), this.redirectToLogin = () => {
      const { appHistory: r } = this.appState.state;
      r.push(v.Login.link);
    }, this.redirectToHome = () => {
      const { appHistory: r } = this.appState.state;
      r.push(_.Home.link);
    }, this.logoutAndRedirectToLogin = async () => {
      await this.appState.logout(), this.redirectToLogin();
    }, this.resendVerificationLink = async () => {
      const r = this.appState.getSdk().IAM.User();
      try {
        if (this.state.isResending)
          return;
        this.setState({ isResending: !0 });
        const s = await r.sendVerificationLink(k());
        if (s.error)
          throw s.error;
        this.setState({ page: m.enum.checkEmail, alert: null });
      } catch (s) {
        console.error(s), this.setState({
          alert: {
            type: P.danger,
            element: /* @__PURE__ */ e.createElement(U, { error: s, defaultMessage: t("verifyUserPage.error.alert.resend.failed") })
          }
        });
      } finally {
        this.setState({ isResending: !1 });
      }
    }, this.dismissAlert = () => {
      this.setState({ alert: null });
    }, this.renderAlert = (r) => {
      const { alert: s } = this.state;
      return s ? /* @__PURE__ */ e.createElement(S, { type: s.type, onDismiss: this.dismissAlert, className: "mb-4" }, s.element) : null;
    }, this.renderSuccessMessage = () => /* @__PURE__ */ e.createElement(
      o,
      {
        isSuccess: !0,
        title: t("verifyUserPage.success.title"),
        description: t("verifyUserPage.success.desc"),
        buttonText: t("navigation.links.login"),
        onClickButton: this.logoutAndRedirectToLogin
      }
    ), this.renderErrorMessage = (r, s) => {
      const a = this.appState.getUser(), n = !!(a != null && a.userId), d = a == null ? void 0 : a.emailAddress, { isResending: c } = this.state;
      switch (!0) {
        case r === l.enum.failed_to_verify_user_not_found:
          return /* @__PURE__ */ e.createElement(
            o,
            {
              isSuccess: !1,
              title: t("verifyUserPage.error.failed.userNotFound.title"),
              description: t("verifyUserPage.error.failed.userNotFound.desc"),
              buttonText: t("ErrorPage401.buttonAction"),
              onClickButton: this.redirectToHome
            }
          );
        case r === l.enum.failed_to_verify_server_error:
          this.appState.state.appHistory.push(b.Error500.makePath());
          return;
        case !n:
          return /* @__PURE__ */ e.createElement(
            o,
            {
              isSuccess: !1,
              title: t("verifyUserPage.error.failed.title"),
              description: t("verifyUserPage.error.failed.notLogIn.desc"),
              buttonText: t("navigation.links.login"),
              onClickButton: this.redirectToLogin
            }
          );
        case (!!s && d !== s):
          return /* @__PURE__ */ e.createElement(
            o,
            {
              isSuccess: !1,
              title: t("verifyUserPage.error.failed.title"),
              description: t("verifyUserPage.error.failed.wrongAccount.desc"),
              buttonText: t("navigation.links.logout"),
              onClickButton: this.logoutAndRedirectToLogin
            }
          );
        case r === l.enum.failed_to_verify_expired_link:
          return /* @__PURE__ */ e.createElement(
            o,
            {
              isSuccess: !1,
              title: t("verifyUserPage.error.expired.title"),
              description: t("verifyUserPage.error.expired.desc"),
              buttonText: t("verifyUserPage.error.button.resend"),
              onClickButton: this.resendVerificationLink,
              isLoading: c
            }
          );
        case r === l.enum.failed_to_verify_invalid_link:
        default:
          return /* @__PURE__ */ e.createElement(
            o,
            {
              isSuccess: !1,
              title: t("verifyUserPage.error.invalid.title"),
              description: t("verifyUserPage.error.invalid.desc"),
              buttonText: t("verifyUserPage.error.button.resend"),
              onClickButton: this.resendVerificationLink,
              isLoading: c
            }
          );
      }
    }, this.renderCheckEmail = () => {
      const r = new URLSearchParams(location.search).get("email");
      return /* @__PURE__ */ e.createElement("div", { className: "text-center" }, /* @__PURE__ */ e.createElement("p", { className: "messageTitle mb-4" }, t("verifyUserPage.checkEmail.title")), /* @__PURE__ */ e.createElement("p", { className: "messageDesc" }, /* @__PURE__ */ e.createElement(N, { i18nKey: "verifyUserPage.checkEmail.desc" }, "We have sent a verification email to", /* @__PURE__ */ e.createElement("span", { className: "email" }, { email: r }))), /* @__PURE__ */ e.createElement("hr", { className: "my-5 text-[color:rgb(var(--od-rgb-text),0.65)]" }), /* @__PURE__ */ e.createElement("p", { className: "messageDesc" }, t("verifyUserPage.checkEmail.question")), /* @__PURE__ */ e.createElement("a", { onClick: this.resendVerificationLink, className: "cursor-pointer text-sm" }, t("verifyUserPage.checkEmail.resend")));
    }, this.appState = x.getAppState(), this.state = {
      page: m.enum.message,
      alert: null,
      isResending: !1
    };
  }
  componentDidMount() {
    u.updateBackground(`url(${T})`);
  }
  componentWillUnmount() {
    u.updateBackground(null);
  }
  render() {
    const { page: i } = this.state, r = new URLSearchParams(location.search), s = r.get("success") === "true", a = r.get("email") || "", n = r.get("error_message") || "";
    return /* @__PURE__ */ e.createElement("div", { className: "verifyUserPage" }, /* @__PURE__ */ e.createElement("div", { className: "verifyUserContainer" }, /* @__PURE__ */ e.createElement("div", { className: "flex justify-center" }, /* @__PURE__ */ e.createElement("img", { src: C, loading: "lazy" })), /* @__PURE__ */ e.createElement("div", { className: "verifyUserCard" }, this.renderAlert(n), i === m.enum.message && /* @__PURE__ */ e.createElement(e.Fragment, null, s && this.renderSuccessMessage(), !s && this.renderErrorMessage(n, a)), i === m.enum.checkEmail && this.renderCheckEmail())));
  }
}
export {
  D as default
};
