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

// src/pages/shipping-profiles/shipping-profile-create/components/create-shipping-profile-form/create-shipping-profile-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 CreateShippingOptionsSchema = zod.object({
  name: zod.string().min(1),
  type: zod.string().min(1)
});
function CreateShippingProfileForm() {
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const form = useForm({
    defaultValues: {
      name: "",
      type: ""
    },
    resolver: zodResolver(CreateShippingOptionsSchema)
  });
  const { mutateAsync, isPending } = useCreateShippingProfile();
  const handleSubmit = form.handleSubmit(async (values) => {
    await mutateAsync(
      {
        name: values.name,
        type: values.type
      },
      {
        onSuccess: ({ shipping_profile }) => {
          toast.success(
            t("shippingProfile.create.successToast", {
              name: shipping_profile.name
            })
          );
          handleSuccess(
            `/settings/locations/shipping-profiles/${shipping_profile.id}`
          );
        },
        onError: (error) => {
          toast.error(error.message);
        }
      }
    );
  });
  return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, "data-testid": "shipping-profile-create-form", children: /* @__PURE__ */ jsxs(
    KeyboundForm,
    {
      onSubmit: handleSubmit,
      className: "flex h-full flex-col overflow-hidden",
      children: [
        /* @__PURE__ */ jsx(RouteFocusModal.Header, { "data-testid": "shipping-profile-create-form-header" }),
        /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", "data-testid": "shipping-profile-create-form-body", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "mx-auto flex w-full max-w-[720px] flex-col gap-y-8 px-2 py-16", children: [
          /* @__PURE__ */ jsxs("div", { "data-testid": "shipping-profile-create-form-header-section", children: [
            /* @__PURE__ */ jsx(Heading, { className: "capitalize", "data-testid": "shipping-profile-create-form-heading", children: t("shippingProfile.create.header") }),
            /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "shipping-profile-create-form-hint", children: t("shippingProfile.create.hint") })
          ] }),
          /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
            /* @__PURE__ */ jsx(
              Form.Field,
              {
                control: form.control,
                name: "name",
                render: ({ field }) => {
                  return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "shipping-profile-create-form-name-item", children: [
                    /* @__PURE__ */ jsx(Form.Label, { "data-testid": "shipping-profile-create-form-name-label", children: t("fields.name") }),
                    /* @__PURE__ */ jsx(Form.Control, { "data-testid": "shipping-profile-create-form-name-control", children: /* @__PURE__ */ jsx(Input, { ...field, "data-testid": "shipping-profile-create-form-name-input" }) }),
                    /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "shipping-profile-create-form-name-error" })
                  ] });
                }
              }
            ),
            /* @__PURE__ */ jsx(
              Form.Field,
              {
                control: form.control,
                name: "type",
                render: ({ field }) => {
                  return /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "shipping-profile-create-form-type-item", children: [
                    /* @__PURE__ */ jsx(Form.Label, { tooltip: t("shippingProfile.tooltip.type"), "data-testid": "shipping-profile-create-form-type-label", children: t("fields.type") }),
                    /* @__PURE__ */ jsx(Form.Control, { "data-testid": "shipping-profile-create-form-type-control", children: /* @__PURE__ */ jsx(Input, { ...field, "data-testid": "shipping-profile-create-form-type-input" }) }),
                    /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "shipping-profile-create-form-type-error" })
                  ] });
                }
              }
            )
          ] })
        ] }) }) }),
        /* @__PURE__ */ jsx(RouteFocusModal.Footer, { "data-testid": "shipping-profile-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": "shipping-profile-create-form-cancel-button", children: t("actions.cancel") }) }),
          /* @__PURE__ */ jsx(Button, { type: "submit", size: "small", isLoading: isPending, "data-testid": "shipping-profile-create-form-save-button", children: t("actions.save") })
        ] }) })
      ]
    }
  ) });
}

// src/pages/shipping-profiles/shipping-profile-create/shipping-profile-create.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
function ShippingProfileCreate() {
  return /* @__PURE__ */ jsx2(RouteFocusModal, { "data-testid": "shipping-profile-create-modal", children: /* @__PURE__ */ jsx2(CreateShippingProfileForm, {}) });
}
export {
  ShippingProfileCreate as Component
};
