import "./chunk-NXDFDEKP.js";
import {
  CountrySelect
} from "./chunk-7CAFYKKA.js";
import "./chunk-JRTZWK77.js";
import "./chunk-TKGWSUEI.js";
import {
  KeyboundForm
} from "./chunk-SITRHMZZ.js";
import {
  RouteDrawer,
  useRouteModal
} from "./chunk-GDWBOQI5.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import "./chunk-RLRWDHME.js";
import "./chunk-K5324KIX.js";
import "./chunk-FV76G2D7.js";
import "./chunk-GHDLST2P.js";
import "./chunk-YVYYOBAE.js";
import "./chunk-L2NJPDUD.js";
import "./chunk-P7UBW2EI.js";
import "./chunk-MR6REQKT.js";
import "./chunk-EPSDO2MJ.js";
import "./chunk-BHEU34FL.js";
import {
  useMe,
  useUpdateSellerAddress
} from "./chunk-W34KDYZA.js";
import "./chunk-II3CLUXA.js";
import "./chunk-XKEYHWBS.js";
import "./chunk-J2XUEO2E.js";
import "./chunk-656G74I2.js";
import "./chunk-VWPNMEOE.js";
import "./chunk-O72AIZUN.js";
import "./chunk-VUWAOX7H.js";
import "./chunk-5DKUSZQ7.js";
import "./chunk-DIAWPVYS.js";
import "./chunk-4U2BLH45.js";
import "./chunk-YAUGB4LD.js";
import "./chunk-A5DJIOHN.js";
import "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import "./chunk-DTGEFKK4.js";
import "./chunk-NBMM2TZK.js";

// src/pages/settings/store/address/index.tsx
import { Heading } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";

// src/pages/settings/store/address/store-address-form.tsx
import i18n from "i18next";
import { Button, Input, toast } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import * as zod from "zod";
import { FormExtensionZone, useExtendableForm } from "@mercurjs/dashboard-shared";
import { jsx, jsxs } from "react/jsx-runtime";
var StoreAddressSchema = zod.object({
  name: zod.string().min(1, { message: i18n.t("store.address.validation.nameRequired") }),
  address_1: zod.string().optional().or(zod.literal("")),
  address_2: zod.string().optional().or(zod.literal("")),
  city: zod.string().optional().or(zod.literal("")),
  province: zod.string().optional().or(zod.literal("")),
  postal_code: zod.string().optional().or(zod.literal("")),
  country_code: zod.string().min(2, { message: i18n.t("store.address.validation.countryRequired") }).max(2)
});
var StoreAddressForm = ({ seller }) => {
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const address = seller.address;
  const form = useExtendableForm({
    schema: StoreAddressSchema,
    model: "seller",
    zone: "address",
    data: seller,
    defaultValues: {
      name: address?.name ?? "",
      address_1: address?.address_1 ?? "",
      address_2: address?.address_2 ?? "",
      city: address?.city ?? "",
      province: address?.province ?? "",
      postal_code: address?.postal_code ?? "",
      country_code: address?.country_code ?? ""
    }
  });
  const { mutateAsync, isPending } = useUpdateSellerAddress(seller.id);
  const handleSubmit = form.handleSubmit(async (values) => {
    await mutateAsync(
      {
        name: values.name,
        address_1: values.address_1 || null,
        address_2: values.address_2 || null,
        city: values.city || null,
        province: values.province || null,
        postal_code: values.postal_code || null,
        country_code: values.country_code,
        additional_data: values.additional_data
      },
      {
        onSuccess: () => {
          toast.success(
            t("store.address.edit.successToast")
          );
          handleSuccess();
        },
        onError: (error) => {
          toast.error(error.message);
        }
      }
    );
  });
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
    KeyboundForm,
    {
      onSubmit: handleSubmit,
      className: "flex flex-1 flex-col overflow-hidden",
      children: [
        /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-4 overflow-y-auto", children: [
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "name",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { children: t("store.address.nameLabel") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "address_1",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("fields.address") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "address_2",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("fields.address2") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "postal_code",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("fields.postalCode") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "city",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("fields.city") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "country_code",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { children: t("fields.country") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "province",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("fields.state") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            FormExtensionZone,
            {
              model: "seller",
              zone: "address",
              control: form.control,
              data: seller
            }
          )
        ] }),
        /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
          /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: t("actions.cancel") }) }),
          /* @__PURE__ */ jsx(Button, { type: "submit", size: "small", isLoading: isPending, children: t("actions.save") })
        ] }) })
      ]
    }
  ) });
};

// src/pages/settings/store/address/index.tsx
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var Component = () => {
  const { t } = useTranslation2();
  const { seller_member, isPending, isError, error } = useMe();
  const seller = seller_member?.seller;
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsxs2(RouteDrawer, { children: [
    /* @__PURE__ */ jsxs2(RouteDrawer.Header, { children: [
      /* @__PURE__ */ jsx2(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx2(Heading, { children: t("store.address.edit.header") }) }),
      /* @__PURE__ */ jsx2(RouteDrawer.Description, { className: "sr-only", children: t("store.address.edit.description") })
    ] }),
    !isPending && seller && /* @__PURE__ */ jsx2(StoreAddressForm, { seller })
  ] });
};
export {
  Component
};
