import {
  useCreateReturnReason
} from "./chunk-2FGRDEAD.js";
import "./chunk-TKGWSUEI.js";
import {
  KeyboundForm
} from "./chunk-U2ZFCAPX.js";
import {
  RouteFocusModal,
  useRouteModal
} from "./chunk-FWJLS7XD.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import "./chunk-ZBWL72TB.js";
import "./chunk-NBMM2TZK.js";

// src/pages/return-reasons/return-reason-create/components/return-reason-create-form/return-reason-create-form.tsx
import { zodResolver } from "@hookform/resolvers/zod";
import { Button, Heading, Input, Text, Textarea, toast } from "@medusajs/ui";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { z } from "zod";
import { jsx, jsxs } from "react/jsx-runtime";
var ReturnReasonCreateSchema = z.object({
  value: z.string().min(1),
  label: z.string().min(1),
  description: z.string().optional()
});
var ReturnReasonCreateForm = () => {
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const form = useForm({
    defaultValues: {
      value: "",
      label: "",
      description: ""
    },
    resolver: zodResolver(ReturnReasonCreateSchema)
  });
  const { mutateAsync, isPending } = useCreateReturnReason();
  const handleSubmit = form.handleSubmit(async (data) => {
    await mutateAsync(data, {
      onSuccess: ({ return_reason }) => {
        toast.success(
          t("returnReasons.create.successToast", {
            label: return_reason.label
          })
        );
        handleSuccess(`../`);
      },
      onError: (error) => {
        toast.error(error.message);
      }
    });
  });
  return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, "data-testid": "return-reason-create-form", children: /* @__PURE__ */ jsxs(
    KeyboundForm,
    {
      className: "flex size-full flex-col overflow-hidden",
      onSubmit: handleSubmit,
      children: [
        /* @__PURE__ */ jsx(RouteFocusModal.Header, { "data-testid": "return-reason-create-form-header" }),
        /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 justify-center overflow-auto px-6 py-16", "data-testid": "return-reason-create-form-body", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
          /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-1", "data-testid": "return-reason-create-form-header-section", children: [
            /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { "data-testid": "return-reason-create-form-heading", children: t("returnReasons.create.header") }) }),
            /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "return-reason-create-form-subtitle", children: t("returnReasons.create.subtitle") }) })
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "grid gap-4 md:grid-cols-2", children: [
            /* @__PURE__ */ jsx(
              Form.Field,
              {
                control: form.control,
                name: "value",
                render: ({ field }) => {
                  return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "return-reason-create-form-value-item", children: [
                    /* @__PURE__ */ jsx(
                      Form.Label,
                      {
                        tooltip: t("returnReasons.fields.value.tooltip"),
                        "data-testid": "return-reason-create-form-value-label",
                        children: t("returnReasons.fields.value.label")
                      }
                    ),
                    /* @__PURE__ */ jsx(Form.Control, { "data-testid": "return-reason-create-form-value-control", children: /* @__PURE__ */ jsx(
                      Input,
                      {
                        ...field,
                        placeholder: t(
                          "returnReasons.fields.value.placeholder"
                        ),
                        "data-testid": "return-reason-create-form-value-input"
                      }
                    ) }),
                    /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "return-reason-create-form-value-error" })
                  ] });
                }
              }
            ),
            /* @__PURE__ */ jsx(
              Form.Field,
              {
                control: form.control,
                name: "label",
                render: ({ field }) => {
                  return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "return-reason-create-form-label-item", children: [
                    /* @__PURE__ */ jsx(Form.Label, { "data-testid": "return-reason-create-form-label-label", children: t("returnReasons.fields.label.label") }),
                    /* @__PURE__ */ jsx(Form.Control, { "data-testid": "return-reason-create-form-label-control", children: /* @__PURE__ */ jsx(
                      Input,
                      {
                        ...field,
                        placeholder: t(
                          "returnReasons.fields.label.placeholder"
                        ),
                        "data-testid": "return-reason-create-form-label-input"
                      }
                    ) }),
                    /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "return-reason-create-form-label-error" })
                  ] });
                }
              }
            )
          ] }),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "description",
              render: ({ field }) => {
                return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "return-reason-create-form-description-item", children: [
                  /* @__PURE__ */ jsx(Form.Label, { optional: true, "data-testid": "return-reason-create-form-description-label", children: t("returnReasons.fields.description.label") }),
                  /* @__PURE__ */ jsx(Form.Control, { "data-testid": "return-reason-create-form-description-control", children: /* @__PURE__ */ jsx(
                    Textarea,
                    {
                      ...field,
                      placeholder: t(
                        "returnReasons.fields.description.placeholder"
                      ),
                      "data-testid": "return-reason-create-form-description-input"
                    }
                  ) }),
                  /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "return-reason-create-form-description-error" })
                ] });
              }
            }
          )
        ] }) }),
        /* @__PURE__ */ jsx(RouteFocusModal.Footer, { "data-testid": "return-reason-create-form-footer", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2", children: [
          /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", "data-testid": "return-reason-create-form-cancel-button", children: t("actions.cancel") }) }),
          /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, "data-testid": "return-reason-create-form-save-button", children: t("actions.save") })
        ] }) })
      ]
    }
  ) });
};

// src/pages/return-reasons/return-reason-create/return-reason-create.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var ReturnReasonCreate = () => {
  return /* @__PURE__ */ jsx2(RouteFocusModal, { "data-testid": "return-reason-create-modal", children: /* @__PURE__ */ jsx2(ReturnReasonCreateForm, {}) });
};
export {
  ReturnReasonCreate as Component
};
