import {
  AuthLayout
} from "./chunk-QEFPTNPC.js";
import {
  AvatarBox
} from "./chunk-CP5IL4P6.js";
import "./chunk-U2EI2ZLM.js";
import {
  require_dist
} from "./chunk-52KJSIHS.js";
import "./chunk-QHQWEERJ.js";
import "./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 {
  useSelectSeller,
  useSellers
} 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 {
  __toESM
} from "./chunk-NBMM2TZK.js";

// src/pages/store-select/store-select.tsx
import { Children } from "react";
import { ChevronRight, Plus, Spinner } from "@medusajs/icons";
import { Avatar, Heading, StatusBadge, Text } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router-dom";
import { DisplayExtensionZone, DisplayField } from "@mercurjs/dashboard-shared";
var import_types = __toESM(require_dist(), 1);
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var getSellerStatusBadge = (status, t) => {
  switch (status) {
    case import_types.SellerStatus.OPEN:
      return { color: "green", label: t("storeSelect.status.open") };
    case import_types.SellerStatus.PENDING_APPROVAL:
      return {
        color: "orange",
        label: t("storeSelect.status.pendingApproval")
      };
    case import_types.SellerStatus.SUSPENDED:
      return { color: "red", label: t("storeSelect.status.suspended") };
    case import_types.SellerStatus.TERMINATED:
      return null;
    default:
      return { color: "grey", label: status };
  }
};
var StoreSelectLogo = () => {
  return /* @__PURE__ */ jsx(AvatarBox, {});
};
var StoreSelectHeader = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsxs("div", { className: "mb-6 flex flex-col", children: [
    /* @__PURE__ */ jsx(Heading, { children: t("storeSelect.title") }),
    /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: t("storeSelect.subtitle") })
  ] });
};
var StoreSelectList = ({
  seller_members,
  email
}) => {
  const { t } = useTranslation();
  const navigate = useNavigate();
  const { mutateAsync: selectSeller } = useSelectSeller();
  const handleSelect = async (sellerId) => {
    await selectSeller({ seller_id: sellerId });
    navigate("/", { replace: true });
  };
  return /* @__PURE__ */ jsxs("div", { className: "shadow-elevation-card-rest bg-ui-bg-base flex w-full flex-col divide-y rounded-lg", children: [
    seller_members?.filter((member) => member.seller.status !== import_types.SellerStatus.TERMINATED).map((member) => {
      const seller = member.seller;
      const badge = getSellerStatusBadge(seller.status, t);
      return /* @__PURE__ */ jsxs(
        "button",
        {
          onClick: () => handleSelect(seller.id),
          className: "transition-fg flex items-center gap-x-3 px-4 py-3 first:rounded-t-lg enabled:hover:bg-ui-bg-base-hover disabled:cursor-not-allowed disabled:opacity-60",
          children: [
            /* @__PURE__ */ jsx(
              Avatar,
              {
                variant: "squared",
                size: "small",
                src: seller.logo || void 0,
                fallback: seller.name.charAt(0).toUpperCase()
              }
            ),
            /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col items-start", children: [
              /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: seller.name }),
              seller.handle ? /* @__PURE__ */ jsxs(
                Text,
                {
                  size: "xsmall",
                  className: "text-ui-fg-subtle",
                  leading: "compact",
                  children: [
                    "/",
                    seller.handle
                  ]
                }
              ) : null
            ] }),
            /* @__PURE__ */ jsx(
              DisplayField,
              {
                model: "seller",
                zone: "seller-select",
                id: "status",
                data: seller,
                children: badge ? /* @__PURE__ */ jsx(StatusBadge, { color: badge.color, children: badge.label }) : null
              }
            ),
            /* @__PURE__ */ jsx(
              DisplayExtensionZone,
              {
                model: "seller",
                zone: "seller-select",
                data: seller,
                builtInFieldIds: ["status"]
              }
            ),
            /* @__PURE__ */ jsx(ChevronRight, { className: "text-ui-fg-muted" })
          ]
        },
        seller.id
      );
    }),
    /* @__PURE__ */ jsxs(
      "button",
      {
        onClick: () => navigate("/onboarding", { state: { email } }),
        className: "hover:bg-ui-bg-base-hover transition-fg flex items-center justify-center gap-x-2 rounded-b-lg px-4 py-3",
        children: [
          /* @__PURE__ */ jsx(Plus, { className: "text-ui-fg-muted" }),
          /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: t("storeSelect.addNewStore") })
        ]
      }
    )
  ] });
};
var StoreSelectFooter = () => {
  return null;
};
var Root = ({ children }) => {
  const location = useLocation();
  const email = location.state?.email ?? "";
  const { seller_members, isLoading } = useSellers();
  if (isLoading) {
    return /* @__PURE__ */ jsx(AuthLayout, { children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-center", children: /* @__PURE__ */ jsx(Spinner, { className: "text-ui-fg-muted animate-spin" }) }) });
  }
  return /* @__PURE__ */ jsx(AuthLayout, { children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(StoreSelectLogo, {}),
    /* @__PURE__ */ jsxs("div", { className: "mt-8", children: [
      /* @__PURE__ */ jsx(StoreSelectHeader, {}),
      /* @__PURE__ */ jsx(
        StoreSelectList,
        {
          seller_members: seller_members ?? [],
          email
        }
      )
    ] }),
    /* @__PURE__ */ jsx(StoreSelectFooter, {})
  ] }) });
};
var StoreSelectPage = Object.assign(Root, {
  Logo: StoreSelectLogo,
  Header: StoreSelectHeader,
  List: StoreSelectList,
  Footer: StoreSelectFooter
});
export {
  StoreSelectPage
};
