import { jsxDEV } from "react/jsx-dev-runtime";
import { SpinnerContainer, Table, TableRow, TableCell, Button } from "@contember/ui";
import { memo } from "react";
import { EmptyMessage } from "@contember/react-binding-ui";
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/LinkButton.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 (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: 32,
          columnNumber: 13
        }, void 0);
      }
      return /* @__PURE__ */ jsxDEV(SpinnerContainer, { enabled: !RoleRenderer, children: RoleRenderer && /* @__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: 43,
            columnNumber: 13
          }, void 0) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 42,
            columnNumber: 12
          }, void 0),
          /* @__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: 46,
            columnNumber: 13
          }, void 0) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 45,
            columnNumber: 12
          }, void 0),
          /* @__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: 49,
            columnNumber: 13
          }, void 0) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 48,
            columnNumber: 12
          }, void 0),
          /* @__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: 54,
            columnNumber: 13
          }, void 0) }, void 0, false, {
            fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
            lineNumber: 53,
            columnNumber: 12
          }, void 0)
        ] }, member.identity.id, true, {
          fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
          lineNumber: 41,
          columnNumber: 11
        }, void 0);
      }) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
        lineNumber: 38,
        columnNumber: 8
      }, void 0) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
        lineNumber: 36,
        columnNumber: 6
      }, void 0);
    } }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx",
      lineNumber: 29,
      columnNumber: 3
    }, void 0);
  }
);
export {
  MemberList
};
//# sourceMappingURL=MemberList.js.map
