import { jsx, jsxs } from "react/jsx-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__ */ jsx(QueryLoader, { query, children: ({ query: query2 }) => {
      if (query2.data.project.members.length === 0) {
        return /* @__PURE__ */ jsx(EmptyMessage, { children: "No members" });
      }
      return /* @__PURE__ */ jsx(SpinnerContainer, { enabled: !RoleRenderer, children: RoleRenderer && /* @__PURE__ */ jsx(Table, { bare: true, children: query2.data.project.members.map((member) => {
        return /* @__PURE__ */ jsxs(TableRow, { children: [
          /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(Identity, { identity: member.identity }) }),
          /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx(IdentityMembership, { RoleRenderer, memberships: member.memberships }) }),
          /* @__PURE__ */ jsx(TableCell, { shrunk: true, children: /* @__PURE__ */ jsx(LinkButton, { size: "small", to: editIdentityLink, parameters: { identityId: member.identity.id, projectSlug: project }, children: "Edit roles" }) }),
          /* @__PURE__ */ jsx(TableCell, { shrunk: true, children: /* @__PURE__ */ jsx(Button, { size: "small", intent: "danger", onClick: () => removeMember(member.identity.id), children: "Revoke access" }) })
        ] }, member.identity.id);
      }) }) });
    } });
  }
);
export {
  MemberList
};
//# sourceMappingURL=MemberList.js.map
