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,
  useUpdateSellerProfessionalDetails
} 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/professional-details/index.tsx
import { Heading } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";

// src/pages/settings/store/professional-details/store-professional-details-form.tsx
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 StoreProfessionalDetailsSchema = zod.object({
  corporate_name: zod.string().optional().or(zod.literal("")),
  registration_number: zod.string().optional().or(zod.literal("")),
  tax_id: zod.string().optional().or(zod.literal(""))
});
var StoreProfessionalDetailsForm = ({
  seller
}) => {
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const details = seller.professional_details;
  const form = useExtendableForm({
    schema: StoreProfessionalDetailsSchema,
    model: "seller",
    zone: "professional-details",
    data: seller,
    defaultValues: {
      corporate_name: details?.corporate_name ?? "",
      registration_number: details?.registration_number ?? "",
      tax_id: details?.tax_id ?? ""
    }
  });
  const { mutateAsync, isPending } = useUpdateSellerProfessionalDetails(
    seller.id
  );
  const handleSubmit = form.handleSubmit(async (values) => {
    await mutateAsync(
      {
        corporate_name: values.corporate_name || null,
        registration_number: values.registration_number || null,
        tax_id: values.tax_id || null,
        additional_data: values.additional_data
      },
      {
        onSuccess: () => {
          toast.success(
            t("store.professionalDetails.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: "corporate_name",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("store.professionalDetails.fields.corporateName") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "registration_number",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("store.professionalDetails.fields.registrationNumber") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            Form.Field,
            {
              control: form.control,
              name: "tax_id",
              render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
                /* @__PURE__ */ jsx(Form.Label, { optional: true, children: t("store.professionalDetails.fields.taxId") }),
                /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { size: "small", ...field }) }),
                /* @__PURE__ */ jsx(Form.ErrorMessage, {})
              ] })
            }
          ),
          /* @__PURE__ */ jsx(
            FormExtensionZone,
            {
              model: "seller",
              zone: "professional-details",
              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/professional-details/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.professionalDetails.edit.header") }) }),
      /* @__PURE__ */ jsx2(RouteDrawer.Description, { className: "sr-only", children: t("store.professionalDetails.edit.description") })
    ] }),
    !isPending && seller && /* @__PURE__ */ jsx2(StoreProfessionalDetailsForm, { seller })
  ] });
};
export {
  Component
};
