import {
  TabbedForm,
  defineTabMeta,
  useTabbedForm
} from "./chunk-KA3VYXNA.js";
import "./chunk-TKGWSUEI.js";
import "./chunk-U2ZFCAPX.js";
import {
  RouteFocusModal,
  useRouteModal
} from "./chunk-OV7R2AH5.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import "./chunk-3MDRW5MA.js";
import "./chunk-MFL2TZ3W.js";
import "./chunk-YNIIYGL4.js";
import "./chunk-CBHNHLUZ.js";
import "./chunk-VME3CJER.js";
import "./chunk-XMVTX2EN.js";
import "./chunk-5PUHROK4.js";
import "./chunk-TPPONKYW.js";
import "./chunk-DF3OGJAK.js";
import "./chunk-XRDP2SYY.js";
import "./chunk-FNBKEF54.js";
import "./chunk-EHQESDH2.js";
import "./chunk-XKVXLDSJ.js";
import "./chunk-XDZGOUCR.js";
import "./chunk-K4BGK3CO.js";
import "./chunk-YYTI5JIC.js";
import "./chunk-HAFZQK53.js";
import "./chunk-IJWG755C.js";
import {
  useCreateSeller
} from "./chunk-M3YP3NX4.js";
import "./chunk-UU2RQMXS.js";
import "./chunk-O4STPJR2.js";
import "./chunk-R74OHYTB.js";
import "./chunk-22XJUSMM.js";
import "./chunk-OFKUNYQJ.js";
import "./chunk-W5UPPL3W.js";
import {
  useStore
} from "./chunk-LC6TM5OT.js";
import "./chunk-7SJC6BWZ.js";
import "./chunk-N4JU7GWK.js";
import "./chunk-52BRBQMY.js";
import "./chunk-BA2HXHTW.js";
import "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import "./chunk-RIN4CBRB.js";
import "./chunk-NBMM2TZK.js";

// src/pages/stores/store-create/components/store-create-form.tsx
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "@medusajs/ui";
import { Children, useMemo } from "react";
import { useForm } from "react-hook-form";
import { useTranslation as useTranslation3 } from "react-i18next";

// src/pages/stores/store-create/components/schema.ts
import { z } from "zod";
var CreateStoreSchema = z.object({
  name: z.string().min(1),
  email: z.string().email(),
  currency_code: z.string().min(1),
  description: z.string().optional().or(z.literal("")),
  handle: z.string().optional().or(z.literal("")),
  member_email: z.string().email()
});

// src/pages/stores/store-create/components/store-create-details-tab.tsx
import { Heading, Input, Select, Text, Textarea } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
var Root = () => {
  const { t } = useTranslation();
  const form = useTabbedForm();
  const { store } = useStore();
  return /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto px-3", children: /* @__PURE__ */ jsxs("div", { className: "mx-auto flex w-full max-w-[720px] flex-col gap-y-8 px-px py-16", children: [
    /* @__PURE__ */ jsxs("div", { children: [
      /* @__PURE__ */ jsx(Heading, { children: t("stores.create.header", "Create Store") }),
      /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: t(
        "stores.create.hint",
        "Create a new store on the marketplace."
      ) })
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "name",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { children: t("fields.name") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "handle",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("fields.handle") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "email",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { children: t("fields.email") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { type: "email", ...field }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "currency_code",
          render: ({ field: { onChange, ref, ...field } }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { children: t("fields.currency") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(Select, { ...field, onValueChange: onChange, children: [
              /* @__PURE__ */ jsx(Select.Trigger, { ref, children: /* @__PURE__ */ jsx(Select.Value, { placeholder: t("fields.currency") }) }),
              /* @__PURE__ */ jsx(Select.Content, { children: store?.supported_currencies?.map((sc) => /* @__PURE__ */ jsx(
                Select.Item,
                {
                  value: sc.currency_code,
                  children: sc.currency_code.toUpperCase()
                },
                sc.currency_code
              )) })
            ] }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "description",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
            /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("fields.description") }),
            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Textarea, { ...field }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
          ] })
        }
      )
    ] })
  ] }) });
};
Root._tabMeta = defineTabMeta({
  id: "details",
  labelKey: "stores.create.tabs.details",
  validationFields: ["name", "email", "currency_code"]
});
var StoreCreateDetailsTab = Root;

// src/pages/stores/store-create/components/store-create-users-tab.tsx
import { Heading as Heading2, Input as Input2, Text as Text2 } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var Root2 = () => {
  const { t } = useTranslation2();
  const form = useTabbedForm();
  return /* @__PURE__ */ jsx2("div", { className: "flex flex-1 flex-col items-center overflow-y-auto px-3", children: /* @__PURE__ */ jsxs2("div", { className: "mx-auto flex w-full max-w-[720px] flex-col gap-y-8 px-px py-16", children: [
    /* @__PURE__ */ jsxs2("div", { children: [
      /* @__PURE__ */ jsx2(Heading2, { children: t("stores.create.usersHeader", "Users") }),
      /* @__PURE__ */ jsx2(Text2, { size: "small", className: "text-ui-fg-subtle", children: t(
        "stores.create.usersHint",
        "Invite the store owner by email. They will receive an invitation to set up their account."
      ) })
    ] }),
    /* @__PURE__ */ jsx2("div", { className: "flex flex-col gap-y-4", children: /* @__PURE__ */ jsx2(
      Form.Field,
      {
        control: form.control,
        name: "member_email",
        render: ({ field }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
          /* @__PURE__ */ jsx2(Form.Label, { optional: true, children: t("stores.create.ownerEmail", "Owner email") }),
          /* @__PURE__ */ jsx2(Form.Control, { children: /* @__PURE__ */ jsx2(
            Input2,
            {
              type: "email",
              ...field,
              placeholder: "owner@example.com"
            }
          ) }),
          /* @__PURE__ */ jsx2(Form.Hint, { children: t(
            "stores.create.ownerEmailHint",
            "The owner will be granted the Store Administration role."
          ) }),
          /* @__PURE__ */ jsx2(Form.ErrorMessage, {})
        ] })
      }
    ) })
  ] }) });
};
Root2._tabMeta = defineTabMeta({
  id: "users",
  labelKey: "stores.create.tabs.users"
});
var StoreCreateUsersTab = Root2;

// src/pages/stores/store-create/components/store-create-form.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
var StoreCreateForm = ({ children }) => {
  const { t } = useTranslation3();
  const { handleSuccess } = useRouteModal();
  const form = useForm({
    defaultValues: {
      name: "",
      email: "",
      currency_code: "",
      description: "",
      handle: "",
      member_email: ""
    },
    resolver: zodResolver(CreateStoreSchema)
  });
  const { mutateAsync: createSeller, isPending } = useCreateSeller();
  const handleSubmit = form.handleSubmit(async (values) => {
    try {
      await createSeller({
        name: values.name,
        email: values.email,
        currency_code: values.currency_code,
        description: values.description || void 0,
        handle: values.handle || void 0,
        member: {
          email: values.member_email
        }
      });
      toast.success(
        t("stores.create.successToast", "Store created successfully")
      );
      handleSuccess();
    } catch (error) {
      toast.error(error.message);
    }
  });
  const defaultTabs = useMemo(
    () => [
      /* @__PURE__ */ jsx3(StoreCreateDetailsTab, {}, "details"),
      /* @__PURE__ */ jsx3(StoreCreateUsersTab, {}, "users")
    ],
    []
  );
  return /* @__PURE__ */ jsx3(TabbedForm, { form, onSubmit: handleSubmit, isLoading: isPending, children: Children.count(children) > 0 ? children : defaultTabs });
};

// src/pages/stores/store-create/index.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root3 = () => {
  return /* @__PURE__ */ jsx4(RouteFocusModal, { children: /* @__PURE__ */ jsx4(StoreCreateForm, {}) });
};
var StoreCreatePage = Object.assign(Root3, {
  Form: StoreCreateForm,
  DetailsTab: StoreCreateDetailsTab,
  UsersTab: StoreCreateUsersTab,
  Tab: TabbedForm.Tab
});
var Component = Root3;
export {
  Component,
  CreateStoreSchema,
  StoreCreatePage
};
