import { jsxDEV } from "react/jsx-dev-runtime";
import { ContainerSpinner, Table, TableRow, TableCell, Button } from "@contember/ui";
import { memo } from "react";
import { useRoleRenderer } from "./RoleRenderer.js";
import { useRemoveMemberIntent } from "./useRemoveMemberIntent.js";
import { IdentityMembership } from "./IdentityMembership.js";
import { QueryLoader } from "../QueryLoader.js";
import { useListMembersQuery } from "../../queries/listUsers.js";
import { LinkButton } from "../../../routing/binding/LinkButton.js";
import { EmptyMessage } from "../../../components/bindingFacade/collections/helpers/EmptyMessage.js";
const MemberList = memo(
  ({ project, createRoleRenderer, editIdentityLink, Identity, memberType }) => {
    const { state: query, refetch: refetchMembersList } = useListMembersQuery(project, memberType);
    const removeMember = useRemoveMemberIntent(project, refetchMembersList);
    const RoleRenderer = useRoleRenderer(createRoleRenderer, query);
    return /* @__PURE__ */ jsxDEV(QueryLoader, { query, children: ({ query: query2 }) => {
      if (!RoleRenderer) {
        return /* @__PURE__ */ jsxDEV(ContainerSpinner, {}, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
          lineNumber: 32,
          columnNumber: 14
        }, globalThis);
      }
      if (query2.data.project.members.length === 0) {
        return /* @__PURE__ */ jsxDEV(EmptyMessage, { children: "No members" }, void 0, false, {
          fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
          lineNumber: 36,
          columnNumber: 14
        }, globalThis);
      }
      return /* @__PURE__ */ jsxDEV(Table, { bare: true, children: query2.data.project.members.map((member) => {
        return /* @__PURE__ */ jsxDEV(TableRow, { children: [
          /* @__PURE__ */ jsxDEV(TableCell, { children: /* @__PURE__ */ jsxDEV(Identity, { identity: member.identity }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 45,
            columnNumber: 12
          }, globalThis) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 44,
            columnNumber: 11
          }, globalThis),
          /* @__PURE__ */ jsxDEV(TableCell, { children: /* @__PURE__ */ jsxDEV(IdentityMembership, { RoleRenderer, memberships: member.memberships }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 48,
            columnNumber: 12
          }, globalThis) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 47,
            columnNumber: 11
          }, globalThis),
          /* @__PURE__ */ jsxDEV(TableCell, { shrunk: true, children: /* @__PURE__ */ jsxDEV(LinkButton, { size: "small", to: editIdentityLink, parameters: { identityId: member.identity.id, projectSlug: project }, children: "Edit roles" }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 51,
            columnNumber: 12
          }, globalThis) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 50,
            columnNumber: 11
          }, globalThis),
          /* @__PURE__ */ jsxDEV(TableCell, { shrunk: true, children: /* @__PURE__ */ jsxDEV(Button, { size: "small", intent: "danger", onClick: () => removeMember(member.identity.id), children: "Revoke access" }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 56,
            columnNumber: 12
          }, globalThis) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 55,
            columnNumber: 11
          }, globalThis)
        ] }, member.identity.id, true, {
          fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
          lineNumber: 43,
          columnNumber: 10
        }, globalThis);
      }) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
        lineNumber: 40,
        columnNumber: 7
      }, globalThis);
    } }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
      lineNumber: 29,
      columnNumber: 4
    }, globalThis);
  }
);
export {
  MemberList
};
//# sourceMappingURL=MemberList.js.map
