import "./chunk-TKGWSUEI.js";
import {
  KeyboundForm
} from "./chunk-SITRHMZZ.js";
import {
  RouteDrawer,
  useRouteModal
} from "./chunk-GDWBOQI5.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import "./chunk-LAVHRER2.js";
import {
  languages
} from "./chunk-QHQWEERJ.js";
import {
  useDocumentDirection
} from "./chunk-Y7QKP6QU.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,
  useUpdateMe
} 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/profile/profile-detail/profile-detail.tsx
import { Children } from "react";
import { WidgetZone, useExtension as useExtension2 } from "@mercurjs/dashboard-shared";

// src/pages/settings/profile/profile-detail/components/profile-general-section/profile-general-section.tsx
import { PencilSquare } from "@medusajs/icons";
import { Container, Heading, Text } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import {
  DisplayExtensionZone,
  DisplayField,
  useExtension
} from "@mercurjs/dashboard-shared";
import { jsx, jsxs } from "react/jsx-runtime";
var ProfileGeneralSection = () => {
  const { i18n, t } = useTranslation();
  const memberLinks = useExtension().getLinks("member");
  const meQuery = memberLinks.length ? { fields: memberLinks.map((link) => `+member.${link}.*`).join(",") } : void 0;
  const { seller_member } = useMe(meQuery);
  const member = seller_member?.member;
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx(Heading, { children: t("profile.domain") }),
        /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: t("profile.manageYourProfileDetails") })
      ] }),
      /* @__PURE__ */ jsx(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  label: t("actions.edit"),
                  to: "edit",
                  icon: /* @__PURE__ */ jsx(PencilSquare, {})
                }
              ]
            }
          ]
        }
      )
    ] }),
    /* @__PURE__ */ jsx(DisplayField, { model: "member", zone: "general", id: "first_name", data: member, children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4", children: [
      /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: t("profile.fields.firstName", "First name") }),
      /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: member?.first_name || "-" })
    ] }) }),
    /* @__PURE__ */ jsx(DisplayField, { model: "member", zone: "general", id: "last_name", data: member, children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4", children: [
      /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: t("profile.fields.lastName", "Last name") }),
      /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: member?.last_name || "-" })
    ] }) }),
    /* @__PURE__ */ jsx(DisplayField, { model: "member", zone: "general", id: "language", data: member, children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4", children: [
      /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: t("profile.fields.languageLabel") }),
      /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: languages.find((lang) => lang.code === i18n.language)?.display_name || "-" })
    ] }) }),
    /* @__PURE__ */ jsx(
      DisplayExtensionZone,
      {
        model: "member",
        zone: "general",
        data: member,
        builtInFieldIds: ["first_name", "last_name", "language"]
      }
    )
  ] });
};

// src/pages/settings/profile/profile-detail/profile-detail.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var Root = ({ children }) => {
  const memberLinks = useExtension2().getLinks("member");
  const meQuery = memberLinks.length ? { fields: memberLinks.map((link) => `+member.${link}.*`).join(",") } : void 0;
  const { seller_member } = useMe(meQuery);
  const member = seller_member?.member;
  return Children.count(children) > 0 ? /* @__PURE__ */ jsx2(SingleColumnPage, { children }) : /* @__PURE__ */ jsx2(SingleColumnPage, { children: /* @__PURE__ */ jsx2(WidgetZone, { id: "profile.detail.main", data: member, children: /* @__PURE__ */ jsx2(ProfileGeneralSection, {}) }) });
};
var ProfileDetailPage = Object.assign(Root, {
  GeneralSection: ProfileGeneralSection
});

// src/pages/settings/profile/profile-edit/profile-edit.tsx
import { Heading as Heading2 } from "@medusajs/ui";
import { useTranslation as useTranslation3 } from "react-i18next";

// src/pages/settings/profile/profile-edit/components/edit-profile-form/edit-profile-form.tsx
import { Button, Input, Select, toast } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";
import * as zod from "zod";
import {
  FormExtensionZone,
  useExtendableForm,
  useExtension as useExtension3
} from "@mercurjs/dashboard-shared";
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
var EditProfileSchema = zod.object({
  first_name: zod.string().optional().or(zod.literal("")),
  last_name: zod.string().optional().or(zod.literal("")),
  language: zod.string()
});
var EditProfileForm = () => {
  const { t, i18n } = useTranslation2();
  const { handleSuccess } = useRouteModal();
  const direction = useDocumentDirection();
  const memberLinks = useExtension3().getLinks("member");
  const meQuery = memberLinks.length ? { fields: memberLinks.map((link) => `+member.${link}.*`).join(",") } : void 0;
  const { seller_member } = useMe(meQuery);
  const member = seller_member?.member;
  const form = useExtendableForm({
    schema: EditProfileSchema,
    model: "member",
    zone: "edit",
    data: member,
    defaultValues: {
      first_name: member?.first_name ?? "",
      last_name: member?.last_name ?? "",
      language: i18n.language
    }
  });
  const sortedLanguages = languages.sort(
    (a, b) => a.display_name.localeCompare(b.display_name)
  );
  const { mutateAsync: updateMe, isPending } = useUpdateMe();
  const handleSubmit = form.handleSubmit(async (values) => {
    await updateMe(
      {
        first_name: values.first_name || null,
        last_name: values.last_name || null,
        additional_data: values.additional_data
      },
      {
        onSuccess: async () => {
          await i18n.changeLanguage(values.language);
          toast.success(t("profile.toast.edit"));
          handleSuccess();
        },
        onError: (error) => {
          toast.error(error.message);
        }
      }
    );
  });
  return /* @__PURE__ */ jsx3(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs2(KeyboundForm, { onSubmit: handleSubmit, className: "flex flex-1 flex-col", children: [
    /* @__PURE__ */ jsx3(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-y-8", children: [
      /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-2 gap-x-3", children: [
        /* @__PURE__ */ jsx3(
          Form.Field,
          {
            control: form.control,
            name: "first_name",
            render: ({ field }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
              /* @__PURE__ */ jsx3(Form.Label, { optional: true, children: t("profile.fields.firstName", "First name") }),
              /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(Input, { autoComplete: "given-name", ...field }) }),
              /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
            ] })
          }
        ),
        /* @__PURE__ */ jsx3(
          Form.Field,
          {
            control: form.control,
            name: "last_name",
            render: ({ field }) => /* @__PURE__ */ jsxs2(Form.Item, { children: [
              /* @__PURE__ */ jsx3(Form.Label, { optional: true, children: t("profile.fields.lastName", "Last name") }),
              /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsx3(Input, { autoComplete: "family-name", ...field }) }),
              /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
            ] })
          }
        )
      ] }),
      /* @__PURE__ */ jsx3(
        Form.Field,
        {
          control: form.control,
          name: "language",
          render: ({ field: { ref, ...field } }) => /* @__PURE__ */ jsxs2(Form.Item, { className: "gap-y-4", children: [
            /* @__PURE__ */ jsxs2("div", { children: [
              /* @__PURE__ */ jsx3(Form.Label, { children: t("profile.fields.languageLabel") }),
              /* @__PURE__ */ jsx3(Form.Hint, { children: t("profile.edit.languageHint") })
            ] }),
            /* @__PURE__ */ jsxs2("div", { children: [
              /* @__PURE__ */ jsx3(Form.Control, { children: /* @__PURE__ */ jsxs2(
                Select,
                {
                  dir: direction,
                  ...field,
                  onValueChange: field.onChange,
                  children: [
                    /* @__PURE__ */ jsx3(Select.Trigger, { ref, className: "py-1 text-[13px]", children: /* @__PURE__ */ jsx3(
                      Select.Value,
                      {
                        placeholder: t("profile.edit.languagePlaceholder"),
                        children: sortedLanguages.find(
                          (language) => language.code === field.value
                        )?.display_name
                      }
                    ) }),
                    /* @__PURE__ */ jsx3(Select.Content, { children: sortedLanguages.map((language) => /* @__PURE__ */ jsx3(
                      Select.Item,
                      {
                        value: language.code,
                        children: language.display_name
                      },
                      language.code
                    )) })
                  ]
                }
              ) }),
              /* @__PURE__ */ jsx3(Form.ErrorMessage, {})
            ] })
          ] })
        }
      ),
      /* @__PURE__ */ jsx3(
        FormExtensionZone,
        {
          model: "member",
          zone: "edit",
          control: form.control,
          data: member
        }
      )
    ] }) }),
    /* @__PURE__ */ jsx3(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-x-2", children: [
      /* @__PURE__ */ jsx3(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx3(Button, { size: "small", variant: "secondary", children: t("actions.cancel") }) }),
      /* @__PURE__ */ jsx3(Button, { size: "small", type: "submit", isLoading: isPending, children: t("actions.save") })
    ] }) })
  ] }) });
};

// src/pages/settings/profile/profile-edit/profile-edit.tsx
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
var ProfileEdit = () => {
  const { t } = useTranslation3();
  return /* @__PURE__ */ jsxs3(RouteDrawer, { children: [
    /* @__PURE__ */ jsx4(RouteDrawer.Header, { className: "capitalize", children: /* @__PURE__ */ jsx4(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx4(Heading2, { children: t("profile.edit.header") }) }) }),
    /* @__PURE__ */ jsx4(EditProfileForm, {})
  ] });
};
export {
  ProfileDetailPage,
  ProfileEdit
};
