import "./chunk-TKGWSUEI.js";
import {
  KeyboundForm
} from "./chunk-U2ZFCAPX.js";
import {
  RouteFocusModal,
  useRouteModal
} from "./chunk-OV7R2AH5.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import {
  useCreateProductType
} from "./chunk-5PUHROK4.js";
import "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import "./chunk-RIN4CBRB.js";
import "./chunk-NBMM2TZK.js";

// src/pages/product-types/product-type-create/components/create-product-type-form/create-product-type-form.tsx
import { zodResolver } from "@hookform/resolvers/zod";
import { Button, Heading, Input, Text, 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 CreateProductTypeSchema = z.object({
  value: z.string().min(1)
});
var CreateProductTypeForm = () => {
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const form = useForm({
    defaultValues: {
      value: ""
    },
    resolver: zodResolver(CreateProductTypeSchema)
  });
  const { mutateAsync, isPending } = useCreateProductType();
  const handleSubmit = form.handleSubmit(
    async (values) => {
      await mutateAsync(values, {
        onSuccess: ({ product_type }) => {
          toast.success(
            t("productTypes.create.successToast", {
              value: product_type.value.trim()
            })
          );
          handleSuccess(`/settings/product-types/${product_type.id}`);
        },
        onError: (e) => {
          toast.error(e.message);
        }
      });
    }
  );
  return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, "data-testid": "product-type-create-form", children: /* @__PURE__ */ jsxs(KeyboundForm, { onSubmit: handleSubmit, className: "flex h-full flex-col", children: [
    /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-col items-center overflow-auto p-16", "data-testid": "product-type-create-form-body", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", children: [
      /* @__PURE__ */ jsxs("div", { "data-testid": "product-type-create-form-header-section", children: [
        /* @__PURE__ */ jsx(Heading, { "data-testid": "product-type-create-form-heading", children: t("productTypes.create.header") }),
        /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "product-type-create-form-hint", children: t("productTypes.create.hint") })
      ] }),
      /* @__PURE__ */ jsx("div", { className: "grid grid-cols-1 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": "product-type-create-form-value-item", children: [
              /* @__PURE__ */ jsx(Form.Label, { "data-testid": "product-type-create-form-value-label", children: t("productTypes.fields.value") }),
              /* @__PURE__ */ jsx(Form.Control, { "data-testid": "product-type-create-form-value-control", children: /* @__PURE__ */ jsx(Input, { ...field, "data-testid": "product-type-create-form-value-input" }) }),
              /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "product-type-create-form-value-error" })
            ] });
          }
        }
      ) })
    ] }) }),
    /* @__PURE__ */ jsx(RouteFocusModal.Footer, { "data-testid": "product-type-create-form-footer", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
      /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", "data-testid": "product-type-create-form-cancel-button", children: t("actions.cancel") }) }),
      /* @__PURE__ */ jsx(
        Button,
        {
          size: "small",
          variant: "primary",
          type: "submit",
          isLoading: isPending,
          "data-testid": "product-type-create-form-create-button",
          children: t("actions.create")
        }
      )
    ] }) })
  ] }) });
};

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