"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const react = require("react");
const DisableOtpForm = require("./DisableOtpForm.cjs");
const ui = require("@contember/ui");
const PrepareOtpForm = require("./PrepareOtpForm.cjs");
const ConfirmOtpForm = require("./ConfirmOtpForm.cjs");
const qrcode = require("qrcode-generator");
const useIdentity = require("../../../components/Identity/useIdentity.cjs");
const OtpManagement = () => {
  const identity = useIdentity.useIdentity();
  const [initializingOtp, setInitializingOtp] = react.useState(false);
  const [otpUri, setOtpUri] = react.useState();
  const person = identity.person;
  if (!person) {
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: "Cannot setup OTP for API key." }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
      lineNumber: 17,
      columnNumber: 10
    }, void 0);
  }
  if (initializingOtp) {
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(
      PrepareOtpForm.PrepareOtpForm,
      {
        onPrepared: ({ otpUri: otpUri2 }) => {
          setInitializingOtp(false);
          setOtpUri(otpUri2);
        },
        isReSetup: person.otpEnabled,
        onCancel: () => setInitializingOtp(false)
      },
      void 0,
      false,
      {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 25,
        columnNumber: 5
      },
      void 0
    ) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
      lineNumber: 24,
      columnNumber: 4
    }, void 0);
  }
  if (otpUri) {
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: [
      /* @__PURE__ */ jsxDevRuntime.jsxDEV("p", { children: "Now scan the following QR code in you application:" }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 38,
        columnNumber: 4
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(QrCode, { data: otpUri }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 41,
        columnNumber: 4
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV("p", { children: "After registering to you application, write down a code from the application." }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 42,
        columnNumber: 4
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(ConfirmOtpForm.ConfirmOtpForm, { onSuccess: () => {
        setOtpUri(void 0);
      } }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 45,
        columnNumber: 4
      }, void 0)
    ] }, void 0, true, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
      lineNumber: 37,
      columnNumber: 10
    }, void 0);
  }
  if (person.otpEnabled) {
    return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: [
      /* @__PURE__ */ jsxDevRuntime.jsxDEV("p", { children: "Two factor authentication is ENABLED." }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 53,
        columnNumber: 4
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(DisableOtpForm.DisableOtpForm, {}, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 56,
        columnNumber: 4
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV("p", { children: "You already have two-factor authentication active. By enabling a new code, the old one will no longer work." }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 57,
        columnNumber: 4
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Button, { onClick: () => setInitializingOtp(true), children: "Setup again" }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
        lineNumber: 58,
        columnNumber: 4
      }, void 0)
    ] }, void 0, true, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
      lineNumber: 52,
      columnNumber: 10
    }, void 0);
  }
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxDevRuntime.jsxDEV("p", { children: "2-Step Verification provides stronger security for your account by requiring a second step of verification when you sign in. In addition to your password, you’ll also need a code generated by an application on your phone." }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
      lineNumber: 62,
      columnNumber: 3
    }, void 0),
    /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Button, { onClick: () => setInitializingOtp(true), children: "Setup two-factor authentication" }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
      lineNumber: 67,
      columnNumber: 3
    }, void 0)
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
    lineNumber: 61,
    columnNumber: 9
  }, void 0);
};
const QrCode = ({ data }) => {
  const code = react.useMemo(() => {
    const qr = qrcode(0, "L");
    qr.addData(data);
    qr.make();
    return qr.createDataURL(4);
  }, [data]);
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV("img", { src: code }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/otp/OtpManagement.tsx",
    lineNumber: 78,
    columnNumber: 9
  }, void 0);
};
exports.OtpManagement = OtpManagement;
//# sourceMappingURL=OtpManagement.cjs.map
