import {
  HandleInput
} from "./chunk-TLE6YHGH.js";
import "./chunk-TKGWSUEI.js";
import {
  KeyboundForm
} from "./chunk-U2ZFCAPX.js";
import {
  RouteFocusModal,
  useRouteModal
} from "./chunk-OV7R2AH5.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import {
  useCreateCollection
} from "./chunk-YYTI5JIC.js";
import "./chunk-BA2HXHTW.js";
import "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import "./chunk-RIN4CBRB.js";
import "./chunk-NBMM2TZK.js";

// src/pages/collections/collection-create/components/create-collection-form/create-collection-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 CreateCollectionSchema = zod.object({
  title: zod.string().min(1),
  handle: zod.string().optional()
});
var CreateCollectionForm = () => {
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const form = useForm({
    defaultValues: {
      title: "",
      handle: ""
    },
    resolver: zodResolver(CreateCollectionSchema)
  });
  const { mutateAsync, isPending } = useCreateCollection();
  const handleSubmit = form.handleSubmit(async (data) => {
    await mutateAsync(data, {
      onSuccess: ({ collection }) => {
        handleSuccess(`/collections/${collection.id}`);
        toast.success(t("collections.createSuccess"));
      },
      onError: (error) => {
        toast.error(error.message);
      }
    });
  });
  return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, "data-testid": "collection-create-form", children: /* @__PURE__ */ jsxs(
    KeyboundForm,
    {
      onSubmit: handleSubmit,
      className: "flex h-full flex-col overflow-hidden",
      children: [
        /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
        /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex size-full flex-col items-center p-16", "data-testid": "collection-create-form-body", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8", "data-testid": "collection-create-form-content", children: [
          /* @__PURE__ */ jsxs("div", { "data-testid": "collection-create-form-header", children: [
            /* @__PURE__ */ jsx(Heading, { "data-testid": "collection-create-form-heading", children: t("collections.createCollection") }),
            /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "collection-create-form-hint", children: t("collections.createCollectionHint") })
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [
            /* @__PURE__ */ jsx(
              Form.Field,
              {
                control: form.control,
                name: "title",
                render: ({ field }) => {
                  return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "collection-create-form-title-item", children: [
                    /* @__PURE__ */ jsx(Form.Label, { "data-testid": "collection-create-form-title-label", children: t("fields.title") }),
                    /* @__PURE__ */ jsx(Form.Control, { "data-testid": "collection-create-form-title-control", children: /* @__PURE__ */ jsx(Input, { autoComplete: "off", ...field, "data-testid": "collection-create-form-title-input" }) }),
                    /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "collection-create-form-title-error" })
                  ] });
                }
              }
            ),
            /* @__PURE__ */ jsx(
              Form.Field,
              {
                control: form.control,
                name: "handle",
                render: ({ field }) => {
                  return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "collection-create-form-handle-item", children: [
                    /* @__PURE__ */ jsx(
                      Form.Label,
                      {
                        optional: true,
                        tooltip: t("collections.handleTooltip"),
                        "data-testid": "collection-create-form-handle-label",
                        children: t("fields.handle")
                      }
                    ),
                    /* @__PURE__ */ jsx(Form.Control, { "data-testid": "collection-create-form-handle-control", children: /* @__PURE__ */ jsx(HandleInput, { ...field, "data-testid": "collection-create-form-handle-input" }) }),
                    /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "collection-create-form-handle-error" })
                  ] });
                }
              }
            )
          ] })
        ] }) }),
        /* @__PURE__ */ jsxs(RouteFocusModal.Footer, { "data-testid": "collection-create-form-footer", children: [
          /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", "data-testid": "collection-create-form-cancel-button", children: t("actions.cancel") }) }),
          /* @__PURE__ */ jsx(
            Button,
            {
              size: "small",
              variant: "primary",
              type: "submit",
              isLoading: isPending,
              "data-testid": "collection-create-form-create-button",
              children: t("actions.create")
            }
          )
        ] })
      ]
    }
  ) });
};

// src/pages/collections/collection-create/collection-create.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var CollectionCreate = () => {
  return /* @__PURE__ */ jsx2(RouteFocusModal, { children: /* @__PURE__ */ jsx2(CreateCollectionForm, {}) });
};
export {
  CollectionCreate as Component
};
