import { AuthAppIcon as p } from "./accelbyte-widgets166.mjs";
import { t as a } from "./accelbyte-widgets58.mjs";
import { Ctx as h } from "./accelbyte-widgets33.mjs";
import e from "react";
import { Trans as r } from "react-i18next";
import { AuthenticatorAppDialog as d } from "./accelbyte-widgets564.mjs";
import { FactorSectionComponent as f } from "./accelbyte-widgets565.mjs";
import { Iam as u } from "@accelbyte/sdk-iam";
const s = "authenticator";
class E extends e.Component {
  constructor(c) {
    super(c), this.disableAuthenticatorFactor = async () => {
      const { onError: t, onUpdated: o, onSuccess: l, closeConfirmDialog: n } = this.props;
      try {
        await u.UsersV4Api(this.webSdk).deleteUserMeMfaAuthenticatorDisable(), l(), n(), o();
      } catch (i) {
        n(), console.error(i), t(i);
      }
    }, this.setAuthenticatorDefault = async () => {
      const { onError: t, onSuccess: o, onUpdated: l, closeConfirmDialog: n } = this.props;
      try {
        await u.UsersV4Api(this.webSdk).postUserMeMfaFactor({ factor: s }), o(), n(), l();
      } catch (i) {
        console.error(i), t(i), n();
      }
    }, this.enableAuthenticationApp = (t) => {
      this.setState({ isAuthenticationAppDialogOpen: t });
    }, this.isAuthenticatorEnabled = () => this.props.enabledFactors ? this.props.enabledFactors.enabled.includes(s) : !1, this.onClickDisable = () => {
      const { setConfirmDialogData: t, closeConfirmDialog: o } = this.props;
      t({
        title: a("AccountPasswordSecurity.2fa.disable.authenticator"),
        message: /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.disable.message.authenticator" }, "Are you sure want to disable ", /* @__PURE__ */ e.createElement("span", { className: "font-semibold" }, "Authenticator App"), "?"),
        cancelBtnLabel: a("AccountPasswordSecurity.2fa.cancelBtn"),
        confirmBtnLabel: a("AccountPasswordSecurity.2fa.disableBtn"),
        onCancel: o,
        onConfirm: this.disableAuthenticatorFactor,
        isOpen: !0
      });
    }, this.onClickDefault = () => {
      const { setConfirmDialogData: t, closeConfirmDialog: o } = this.props;
      t({
        title: a("AccountPasswordSecurity.2fa.confirmation.label"),
        message: /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.authenticator.default.message" }, "Are you sure want to set ", /* @__PURE__ */ e.createElement("span", { className: "font-semibold" }, "Authentication App"), " as default two-factor authentication method?"),
        cancelBtnLabel: a("AccountPasswordSecurity.2fa.cancelBtn"),
        confirmBtnLabel: a("AccountPasswordSecurity.2fa.yesBtn"),
        isOpen: !0,
        onCancel: o,
        onConfirm: this.setAuthenticatorDefault
      });
    }, this.state = {
      isAuthenticationAppDialogOpen: !1
    }, this.webSdk = h.getAppState().getSdk();
  }
  render() {
    const { onSuccess: c, enabledFactors: t, onUpdated: o } = this.props;
    return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
      f,
      {
        icon: /* @__PURE__ */ e.createElement(p, { className: "iconMethod" }),
        title: /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.authenticatorApp" }, "Authenticator App"),
        description: /* @__PURE__ */ e.createElement(r, { i18nKey: "AccountPasswordSecurity.2fa.authenticatorAppDesc" }, "Use an Authenticator app to get free verification codes, even when your phone is offline. Available for Android and iPhone"),
        enabledFactors: t,
        checkBoxLabel: a("AccountPasswordSecurity.2fa.authenticatorAppCheckbox"),
        onClickCheckbox: t && t.default !== s ? this.onClickDefault : void 0,
        isCheckboxDisabled: !!t && t.default === s && t.enabled.length === 1,
        isFactorEnabled: this.isAuthenticatorEnabled(),
        onEnable: () => this.enableAuthenticationApp(!0),
        onDisable: this.onClickDisable,
        FactorValue: s,
        isFirstSection: !0,
        isPreviewMode: this.props.isPreviewMode
      }
    ), /* @__PURE__ */ e.createElement(
      d,
      {
        isOpen: this.state.isAuthenticationAppDialogOpen,
        onClose: () => this.enableAuthenticationApp(!1),
        onSuccess: c,
        onUpdated: o
      }
    ));
  }
}
export {
  E as AuthAppSection
};
