"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 createResetPasswordRequest = require("../../mutations/password/createResetPasswordRequest.cjs");
const reactRouting = require("@contember/react-routing");
const useForm = require("../../lib/useForm.cjs");
const initialValues = {
  email: ""
};
const CreateResetPasswordRequestForm = ({ redirectOnSuccess }) => {
  const redirect = reactRouting.useRedirect();
  const addToast = ui.useShowToast();
  const createResetPasswordRequest$1 = createResetPasswordRequest.useCreateResetPasswordRequest();
  const { register, isSubmitting, onSubmit } = useForm.useForm(initialValues, react.useCallback(
    async (values) => {
      const response = await createResetPasswordRequest$1({
        email: values.email
      });
      if (response.ok) {
        addToast({
          type: "success",
          message: `Check your inbox for the instructions.`,
          dismiss: true
        });
        redirect(redirectOnSuccess);
      } else {
        switch (response.error.code) {
          case "PERSON_NOT_FOUND":
            return addToast({ message: `E-mail not found`, type: "error" });
        }
      }
    },
    [addToast, createResetPasswordRequest$1, redirect, redirectOnSuccess]
  ));
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV("form", { onSubmit, children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Stack, { gap: "large", children: [
    /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.FieldContainer, { label: "E-mail", children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.EmailInput, { ...register("email"), required: true }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/password/CreateResetPasswordRequestForm.tsx",
      lineNumber: 46,
      columnNumber: 6
    }, void 0) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/password/CreateResetPasswordRequestForm.tsx",
      lineNumber: 45,
      columnNumber: 5
    }, void 0),
    /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.FieldContainer, { label: void 0, children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.Button, { distinction: "primary", type: "submit", disabled: isSubmitting, children: "Reset password" }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/password/CreateResetPasswordRequestForm.tsx",
      lineNumber: 49,
      columnNumber: 6
    }, void 0) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/password/CreateResetPasswordRequestForm.tsx",
      lineNumber: 48,
      columnNumber: 5
    }, void 0)
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/password/CreateResetPasswordRequestForm.tsx",
    lineNumber: 44,
    columnNumber: 4
  }, void 0) }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/tenant/components/password/CreateResetPasswordRequestForm.tsx",
    lineNumber: 43,
    columnNumber: 3
  }, void 0);
};
exports.CreateResetPasswordRequestForm = CreateResetPasswordRequestForm;
//# sourceMappingURL=CreateResetPasswordRequestForm.cjs.map
