import { memo, createElement } from "react";
import { ContainerSpinner, Table, TableRow, TableCell, Button } from "@contember/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 { EmptyMessage } from "../../../components/bindingFacade/collections/helpers/EmptyMessage.js";
import { LinkButton } from "../../../routing/binding/LinkButton.js";
const MemberList = memo(({ project, createRoleRenderer, createEditIdentityLink, Identity, memberType }) => {
  const { state: query, refetch: refetchMembersList } = useListMembersQuery(project, memberType);
  const removeMember = useRemoveMemberIntent(project, refetchMembersList);
  const RoleRenderer = useRoleRenderer(createRoleRenderer, query);
  return /* @__PURE__ */ createElement(QueryLoader, {
    query
  }, ({ query: query2 }) => {
    if (!RoleRenderer) {
      return /* @__PURE__ */ createElement(ContainerSpinner, null);
    }
    if (query2.data.project.members.length === 0) {
      return /* @__PURE__ */ createElement(EmptyMessage, null, "No members");
    }
    return /* @__PURE__ */ createElement(Table, {
      bare: true
    }, query2.data.project.members.map((member) => {
      return /* @__PURE__ */ createElement(TableRow, {
        key: member.identity.id
      }, /* @__PURE__ */ createElement(TableCell, null, /* @__PURE__ */ createElement(Identity, {
        identity: member.identity
      })), /* @__PURE__ */ createElement(TableCell, null, /* @__PURE__ */ createElement(IdentityMembership, {
        RoleRenderer,
        memberships: member.memberships
      })), /* @__PURE__ */ createElement(TableCell, {
        shrunk: true
      }, /* @__PURE__ */ createElement(LinkButton, {
        size: "small",
        to: createEditIdentityLink(member.identity.id)
      }, "Edit roles")), /* @__PURE__ */ createElement(TableCell, {
        shrunk: true
      }, /* @__PURE__ */ createElement(Button, {
        size: "small",
        intent: "danger",
        onClick: () => removeMember(member.identity.id)
      }, "Revoke access")));
    }));
  });
});
export { MemberList };
//# sourceMappingURL=MemberList.js.map
