import {
  useMemberTableQuery
} from "./chunk-BI2AYXZQ.js";
import "./chunk-MG4GKUJW.js";
import "./chunk-AYVH6Q5O.js";
import "./chunk-VOHEQ7B5.js";
import "./chunk-DY3XQPHC.js";
import "./chunk-GRH7C3QN.js";
import "./chunk-VKOE5J66.js";
import "./chunk-N3T24SEK.js";
import "./chunk-XBKWFLJG.js";
import {
  DateCell
} from "./chunk-SYNUA6LQ.js";
import "./chunk-BEPAXQMU.js";
import "./chunk-PHOCVOZ5.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import "./chunk-FQERBIVS.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TQNE3E2.js";
import "./chunk-YN3FGNJM.js";
import "./chunk-KCHYLLVG.js";
import "./chunk-CVXKASWV.js";
import "./chunk-THHRRYRS.js";
import "./chunk-LRD242C7.js";
import {
  require_dist
} from "./chunk-52KJSIHS.js";
import "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import "./chunk-LAVHRER2.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 {
  useMe,
  useRemoveSellerMember,
  useSellerMembers
} 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/settings/team/team-list-page.tsx
import { Children as Children3 } from "react";
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/settings/team/_components/team-list-table.tsx
import { Children as Children2 } from "react";
import { Container } from "@medusajs/ui";

// src/pages/settings/team/_components/team-list-header.tsx
import { Children } from "react";
import { Button, Heading, Text } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var TeamListTitle = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsx(Heading, { level: "h2", children: t("users.domain") }),
    /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: t("users.list.empty.description") })
  ] });
};
var TeamListActions = ({
  children
}) => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-x-2", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx(Link, { to: "invite", children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: t("users.invite") }) }) });
};
var TeamListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(TeamListTitle, {}),
    /* @__PURE__ */ jsx(TeamListActions, {})
  ] }) });
};

// src/pages/settings/team/_components/team-list-data-table.tsx
import { useMemo } from "react";
import { Trash } from "@medusajs/icons";
import { keepPreviousData } from "@tanstack/react-query";
import { createColumnHelper } from "@tanstack/react-table";
import { useTranslation as useTranslation2 } from "react-i18next";
import { toast } from "@medusajs/ui";
var import_types = __toESM(require_dist(), 1);
import { jsx as jsx2 } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var ROLE_TRANSLATION_MAP = {
  [import_types.SellerRole.SELLER_ADMINISTRATION]: "users.roles.administration",
  [import_types.SellerRole.INVENTORY_MANAGEMENT]: "users.roles.inventoryManagement",
  [import_types.SellerRole.ORDER_MANAGEMENT]: "users.roles.orderManagement",
  [import_types.SellerRole.ACCOUNTING]: "users.roles.accounting",
  [import_types.SellerRole.SUPPORT]: "users.roles.support"
};
var TeamListDataTable = () => {
  const { t } = useTranslation2();
  const { seller_member } = useMe();
  const sellerId = seller_member?.seller?.id;
  const { searchParams, raw } = useMemberTableQuery({ pageSize: PAGE_SIZE });
  const { seller_members, count, isPending, isError, error } = useSellerMembers(
    sellerId,
    searchParams,
    {
      placeholderData: keepPreviousData,
      enabled: !!sellerId
    }
  );
  const columns = useColumns(sellerId);
  const { table } = useDataTable({
    data: seller_members ?? [],
    columns,
    enablePagination: true,
    count,
    pageSize: PAGE_SIZE,
    getRowId: (row) => row.id
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx2(
    _DataTable,
    {
      table,
      columns,
      count,
      pageSize: PAGE_SIZE,
      pagination: true,
      isLoading: isPending,
      queryObject: raw,
      orderBy: [
        { key: "created_at", label: t("fields.createdAt") },
        { key: "updated_at", label: t("fields.updatedAt") }
      ],
      noRecords: {
        message: t("users.list.empty.description")
      }
    }
  );
};
var columnHelper = createColumnHelper();
var useColumns = (sellerId) => {
  const { t } = useTranslation2();
  return useMemo(
    () => [
      columnHelper.accessor("member.email", {
        header: () => /* @__PURE__ */ jsx2("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsx2("span", { children: t("fields.email") }) }),
        cell: ({ row }) => {
          return /* @__PURE__ */ jsx2("div", { className: "flex size-full items-center overflow-hidden", children: /* @__PURE__ */ jsx2("span", { className: "truncate", children: row.original.member?.email }) });
        }
      }),
      columnHelper.accessor("role_id", {
        header: () => /* @__PURE__ */ jsx2("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsx2("span", { children: t("fields.role") }) }),
        cell: ({ row }) => {
          const roleId = row.original.role_id;
          const translationKey = ROLE_TRANSLATION_MAP[roleId];
          const label = translationKey ? t(translationKey) : "-";
          return /* @__PURE__ */ jsx2("div", { className: "flex size-full items-center overflow-hidden", children: /* @__PURE__ */ jsx2("span", { className: "truncate", children: label }) });
        }
      }),
      columnHelper.accessor("created_at", {
        header: () => /* @__PURE__ */ jsx2("div", { className: "flex h-full w-full items-center", children: /* @__PURE__ */ jsx2("span", { children: t("fields.createdAt") }) }),
        cell: ({ getValue }) => {
          const date = getValue();
          return /* @__PURE__ */ jsx2(DateCell, { date: date ? new Date(date) : null });
        }
      }),
      columnHelper.display({
        id: "actions",
        cell: ({ row }) => {
          return /* @__PURE__ */ jsx2(MemberActions, { member: row.original, sellerId });
        }
      })
    ],
    [t, sellerId]
  );
};
var MemberActions = ({
  member,
  sellerId
}) => {
  const { t } = useTranslation2();
  const { mutateAsync: removeMember } = useRemoveSellerMember(
    sellerId,
    member.id
  );
  const handleRemove = async () => {
    try {
      await removeMember();
      toast.success(
        t("users.deleteUserSuccess", {
          name: member.member?.email
        })
      );
    } catch (e) {
      toast.error(e.message);
    }
  };
  return /* @__PURE__ */ jsx2(
    ActionMenu,
    {
      groups: [
        {
          actions: [
            {
              icon: /* @__PURE__ */ jsx2(Trash, {}),
              label: t("actions.remove"),
              onClick: handleRemove
            }
          ]
        }
      ]
    }
  );
};

// src/pages/settings/team/_components/team-list-table.tsx
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
var TeamListTable = ({ children }) => {
  return /* @__PURE__ */ jsx3(Container, { className: "divide-y p-0", children: Children2.count(children) > 0 ? children : /* @__PURE__ */ jsxs2(Fragment2, { children: [
    /* @__PURE__ */ jsx3(TeamListHeader, {}),
    /* @__PURE__ */ jsx3(TeamListDataTable, {})
  ] }) });
};

// src/pages/settings/team/team-list-page.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx4(SingleColumnPage, { hasOutlet: true, children: /* @__PURE__ */ jsx4(WidgetZone, { id: "team.list", children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx4(TeamListTable, {}) }) });
};
var TeamListPage = Object.assign(Root, {
  Table: TeamListTable,
  Header: TeamListHeader,
  HeaderTitle: TeamListTitle,
  HeaderActions: TeamListActions,
  DataTable: TeamListDataTable
});
export {
  TeamListPage
};
