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

// src/pages/customer-groups/customer-group-create/components/create-customer-group-form/create-customer-group-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 * as zod from "zod";
import { jsx, jsxs } from "react/jsx-runtime";
var CreateCustomerGroupSchema = zod.object({
  name: zod.string().min(1)
});
var CreateCustomerGroupForm = () => {
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const form = useForm({
    defaultValues: {
      name: ""
    },
    resolver: zodResolver(CreateCustomerGroupSchema)
  });
  const { mutateAsync, isPending } = useCreateCustomerGroup();
  const handleSubmit = form.handleSubmit(async (data) => {
    await mutateAsync(
      {
        name: data.name
      },
      {
        onSuccess: ({ customer_group }) => {
          toast.success(
            t("customerGroups.create.successToast", {
              name: customer_group.name
            })
          );
          handleSuccess(`/customer-groups/${customer_group.id}`);
        },
        onError: (error) => {
          toast.error(error.message);
        }
      }
    );
  });
  return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, "data-testid": "create-customer-group-form", children: /* @__PURE__ */ jsxs(
    KeyboundForm,
    {
      className: "flex h-full flex-col overflow-hidden",
      onSubmit: handleSubmit,
      "data-testid": "create-customer-group-form-keybound",
      children: [
        /* @__PURE__ */ jsx(RouteFocusModal.Header, { "data-testid": "create-customer-group-form-header" }),
        /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-col items-center pt-[72px]", "data-testid": "create-customer-group-form-body", children: /* @__PURE__ */ jsxs("div", { className: "flex size-full max-w-[720px] flex-col gap-y-8", "data-testid": "create-customer-group-form-content", children: [
          /* @__PURE__ */ jsxs("div", { "data-testid": "create-customer-group-form-header-section", children: [
            /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { "data-testid": "create-customer-group-form-title", children: t("customerGroups.create.header") }) }),
            /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "create-customer-group-form-hint", children: t("customerGroups.create.hint") }) })
          ] }),
          /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 gap-4", "data-testid": "create-customer-group-form-fields", children: /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "name",
              render: ({ field }) => {
                return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "create-customer-group-form-name-item", children: [
                  /* @__PURE__ */ jsx(Form.Label, { "data-testid": "create-customer-group-form-name-label", children: t("fields.name") }),
                  /* @__PURE__ */ jsx(Form.Control, { "data-testid": "create-customer-group-form-name-control", children: /* @__PURE__ */ jsx(Input, { ...field, "data-testid": "create-customer-group-form-name-input" }) }),
                  /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "create-customer-group-form-name-error" })
                ] });
              }
            }
          ) })
        ] }) }),
        /* @__PURE__ */ jsx(RouteFocusModal.Footer, { "data-testid": "create-customer-group-form-footer", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", "data-testid": "create-customer-group-form-footer-actions", children: [
          /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", "data-testid": "create-customer-group-form-cancel-button", children: t("actions.cancel") }) }),
          /* @__PURE__ */ jsx(
            Button,
            {
              type: "submit",
              variant: "primary",
              size: "small",
              isLoading: isPending,
              "data-testid": "create-customer-group-form-submit-button",
              children: t("actions.create")
            }
          )
        ] }) })
      ]
    }
  ) });
};

// src/pages/customer-groups/customer-group-create/customer-group-create.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var CustomerGroupCreate = () => {
  return /* @__PURE__ */ jsx2(RouteFocusModal, { children: /* @__PURE__ */ jsx2(CreateCustomerGroupForm, {}) });
};
export {
  CustomerGroupCreate as Component
};
