"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const ui = require("@contember/ui");
const react = require("react");
const reactIdentity = require("@contember/react-identity");
const disableOtp = require("../../mutations/otp/disableOtp.cjs");
const reactRouting = require("@contember/react-routing");
const useForm = require("../../lib/useForm.cjs");
const initialValues = {};
const DisableOtpForm = ({ redirectOnSuccess }) => {
  const redirect = reactRouting.useRedirect();
  const addToast = ui.useShowToast();
  const disableOtp$1 = disableOtp.useDisableOtp();
  const { refreshIdentity } = reactIdentity.useIdentityMethods();
  const { isSubmitting, onSubmit } = useForm.useForm(
    initialValues,
    react.useCallback(
      async () => {
        if (!confirm("Are you sure?")) {
          return;
        }
        const response = await disableOtp$1({});
        if (response.ok) {
          addToast({
            type: "success",
            message: `Two-factor authentication has been disabled`,
            dismiss: true
          });
          refreshIdentity();
          redirectOnSuccess && redirect(redirectOnSuccess);
        } else {
          switch (response.error.code) {
            case "OTP_NOT_ACTIVE":
              return addToast({ message: `Two factor is not active`, type: "error" });
          }
        }
      },
      [addToast, disableOtp$1, redirect, redirectOnSuccess, refreshIdentity]
    )
  );
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV("form", { onSubmit, children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Button, { intent: "danger", type: "submit", disabled: isSubmitting, children: "Disable two-factor" }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/DisableOtpForm.tsx",
    lineNumber: 51,
    columnNumber: 4
  }, void 0) }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/DisableOtpForm.tsx",
    lineNumber: 50,
    columnNumber: 3
  }, void 0);
};
exports.DisableOtpForm = DisableOtpForm;
//# sourceMappingURL=DisableOtpForm.cjs.map
