"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 prepareOtp = require("../../mutations/otp/prepareOtp.cjs");
const useForm = require("../../lib/useForm.cjs");
const initialValues = {
  label: "Contember Admin"
};
const PrepareOtpForm = ({ onPrepared, isReSetup, onCancel }) => {
  const addToast = ui.useShowToast();
  const prepareOtp$1 = prepareOtp.usePrepareOtp();
  const { isSubmitting, onSubmit, register } = useForm.useForm(
    initialValues,
    react.useCallback(
      async (values) => {
        const response = await prepareOtp$1({ label: values.label });
        if (response.ok) {
          onPrepared(response.result);
        } else {
          switch (response.error.code) {
            case "OTP_NOT_ACTIVE":
              return addToast({ message: `Two factor is not active`, type: "error", dismiss: true });
          }
        }
      },
      [addToast, prepareOtp$1, onPrepared]
    )
  );
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV("form", { onSubmit, children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Stack, { gap: "large", children: [
    /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.FieldContainer, { label: "Label for an identification in two-factor app", children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.TextInput, { ...register("label") }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
      lineNumber: 40,
      columnNumber: 6
    }, void 0) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
      lineNumber: 39,
      columnNumber: 5
    }, void 0),
    isReSetup && /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Message, { important: true, padding: true, intent: "warn", children: 'You already have two-factor authentication active. By clicking "Continue", the old one will no longer work.' }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
      lineNumber: 44,
      columnNumber: 6
    }, void 0) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
      lineNumber: 43,
      columnNumber: 19
    }, void 0),
    /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Stack, { horizontal: true, style: { alignSelf: "flex-end" }, children: [
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Button, { type: "submit", distinction: "seamless", onClick: onCancel, children: "Cancel" }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
        lineNumber: 50,
        columnNumber: 6
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Button, { intent: isReSetup ? "danger" : void 0, distinction: "primary", type: "submit", disabled: isSubmitting, children: "Continue" }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
        lineNumber: 54,
        columnNumber: 6
      }, void 0)
    ] }, void 0, true, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
      lineNumber: 49,
      columnNumber: 5
    }, void 0)
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
    lineNumber: 38,
    columnNumber: 4
  }, void 0) }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/PrepareOtpForm.tsx",
    lineNumber: 37,
    columnNumber: 3
  }, void 0);
};
exports.PrepareOtpForm = PrepareOtpForm;
//# sourceMappingURL=PrepareOtpForm.cjs.map
