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 { jsxDEV } from "react/jsx-dev-runtime";
import { useListMembersQuery } from "../../queries/listUsers.js";
import { EmptyMessage } from "../../../components/bindingFacade/collections/helpers/EmptyMessage.js";
import { LinkButton } from "../../../routing/binding/LinkButton.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/tenant/components/member/MemberList.tsx";
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: _jsxFileName,
          lineNumber: 29,
          columnNumber: 14
        }, void 0);
      }
      if (query2.data.project.members.length === 0) {
        return /* @__PURE__ */ jsxDEV(EmptyMessage, {
          children: "No members"
        }, void 0, false, {
          fileName: _jsxFileName,
          lineNumber: 33,
          columnNumber: 14
        }, void 0);
      }
      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: _jsxFileName,
                lineNumber: 42,
                columnNumber: 12
              }, void 0)
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 41,
              columnNumber: 11
            }, void 0), /* @__PURE__ */ jsxDEV(TableCell, {
              children: /* @__PURE__ */ jsxDEV(IdentityMembership, {
                RoleRenderer,
                memberships: member.memberships
              }, void 0, false, {
                fileName: _jsxFileName,
                lineNumber: 45,
                columnNumber: 12
              }, void 0)
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 44,
              columnNumber: 11
            }, 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: _jsxFileName,
                lineNumber: 48,
                columnNumber: 12
              }, void 0)
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 47,
              columnNumber: 11
            }, 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: _jsxFileName,
                lineNumber: 53,
                columnNumber: 12
              }, void 0)
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 52,
              columnNumber: 11
            }, void 0)]
          }, member.identity.id, true, {
            fileName: _jsxFileName,
            lineNumber: 40,
            columnNumber: 10
          }, void 0);
        })
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 37,
        columnNumber: 7
      }, void 0);
    }
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 26,
    columnNumber: 4
  }, void 0);
});
export {
  MemberList
};
//# sourceMappingURL=MemberList.js.map
