import { Alert as s } from "./accelbyte-widgets123.mjs";
import { CommonError as c } from "./accelbyte-widgets124.mjs";
import { Ctx as l } from "./accelbyte-widgets33.mjs";
import { AlertType as n } from "./accelbyte-widgets128.mjs";
import { Iam as m } from "@accelbyte/sdk-iam";
import t from "react";
import { Trans as r } from "react-i18next";
import { AccountMainSection as u, AccountMainSectionHeader as d, AccountMainSectionBody as h } from "./accelbyte-widgets122.mjs";
import { AuthAppSection as f } from "./accelbyte-widgets446.mjs";
import { BackupCodesSectionComponent as p } from "./accelbyte-widgets447.mjs";
import { ConfirmationDialog as g } from "./accelbyte-widgets448.mjs";
import { EmailAuthSection as E } from "./accelbyte-widgets449.mjs";
import "./accelbyte-widgets450.mjs";
class N extends t.Component {
  constructor(o) {
    super(o), this.getEnabledFactor = async () => {
      try {
        const e = await m.UsersV4Api(this.webSdk).getUsersMeMfaFactor();
        this.setState({ enabledFactors: e });
      } catch (e) {
        console.error(e), this.setState({ enabledFactors: null });
      }
    }, this.onSuccess = () => {
      this.setState({
        alert: {
          type: n.success,
          element: /* @__PURE__ */ t.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.updated" }, "Two-factor authentication has been updated.")
        }
      });
    }, this.onError = (e) => {
      this.setState({
        alert: {
          type: n.danger,
          element: /* @__PURE__ */ t.createElement(c, { error: e })
        }
      });
    }, this.setConfirmDialogInfo = (e) => {
      this.setState({ confirmDialogData: e });
    }, this.closeConfirmDialog = () => {
      this.setState({ confirmDialogData: null });
    }, this.state = {
      alert: null,
      enabledFactors: null,
      confirmDialogData: null
    }, this.webSdk = l.getAppState().getSdk();
  }
  componentDidMount() {
    this.props.isPreviewMode || this.getEnabledFactor();
  }
  render() {
    const { alert: o, enabledFactors: e, confirmDialogData: i } = this.state, { isPreviewMode: a } = this.props;
    return /* @__PURE__ */ t.createElement(t.Fragment, null, /* @__PURE__ */ t.createElement(u, { className: "twoFactorAuthenticator" }, /* @__PURE__ */ t.createElement(d, null, /* @__PURE__ */ t.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.title" }, "Two-Factor Authentication")), /* @__PURE__ */ t.createElement(h, { className: "w-full" }, !!o && /* @__PURE__ */ t.createElement("div", { className: "mb-2" }, /* @__PURE__ */ t.createElement(s, { type: o.type, onDismiss: () => this.setState({ alert: null }) }, o.element)), /* @__PURE__ */ t.createElement("div", { className: "mb-2 text-[color:rgb(var(--od-rgb-text),0.65)]" }, /* @__PURE__ */ t.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.desc" }, "Two-Factor Authentication is required to add protection to your account from unauthorized access.")), /* @__PURE__ */ t.createElement("div", { className: "mb-10" }, /* @__PURE__ */ t.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.availableMethod" }, "Available authentication method:")), /* @__PURE__ */ t.createElement(
      f,
      {
        onError: this.onError,
        onSuccess: this.onSuccess,
        enabledFactors: e,
        onUpdated: this.getEnabledFactor,
        setConfirmDialogData: this.setConfirmDialogInfo,
        closeConfirmDialog: this.closeConfirmDialog,
        isPreviewMode: a
      }
    ), /* @__PURE__ */ t.createElement(
      p,
      {
        onSuccess: this.onSuccess,
        onError: this.onError,
        enabledFactors: e,
        onUpdated: this.getEnabledFactor,
        setConfirmDialogData: this.setConfirmDialogInfo,
        closeConfirmDialog: this.closeConfirmDialog,
        isPreviewMode: a
      }
    ), /* @__PURE__ */ t.createElement(
      E,
      {
        onSuccess: this.onSuccess,
        onError: this.onError,
        enabledFactors: e,
        onUpdated: this.getEnabledFactor,
        setConfirmDialogData: this.setConfirmDialogInfo,
        closeConfirmDialog: this.closeConfirmDialog,
        isPreviewMode: a
      }
    ))), i && /* @__PURE__ */ t.createElement(g, { ...i }));
  }
}
export {
  N as TwoFactorAuthenticatorSection
};
