"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const ui = require("@contember/ui");
const react = require("react");
const reactBindingUi = require("@contember/react-binding-ui");
const RoleRenderer = require("./RoleRenderer.cjs");
const useRemoveMemberIntent = require("./useRemoveMemberIntent.cjs");
const IdentityMembership = require("./IdentityMembership.cjs");
const QueryLoader = require("../QueryLoader.cjs");
const listUsers = require("../../queries/listUsers.cjs");
const LinkButton = require("../../../routing/LinkButton.cjs");
const MemberList = react.memo(
  ({ project, createRoleRenderer, editIdentityLink, Identity, memberType }) => {
    const { state: query, refetch: refetchMembersList } = listUsers.useListMembersQuery(project, memberType);
    const removeMember = useRemoveMemberIntent.useRemoveMemberIntent(project, refetchMembersList);
    const RoleRenderer$1 = RoleRenderer.useRoleRenderer(createRoleRenderer, query);
    return /* @__PURE__ */ jsxRuntime.jsx(QueryLoader.QueryLoader, { query, children: ({ query: query2 }) => {
      if (query2.data.project.members.length === 0) {
        return /* @__PURE__ */ jsxRuntime.jsx(reactBindingUi.EmptyMessage, { children: "No members" });
      }
      return /* @__PURE__ */ jsxRuntime.jsx(ui.SpinnerContainer, { enabled: !RoleRenderer$1, children: RoleRenderer$1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Table, { bare: true, children: query2.data.project.members.map((member) => {
        return /* @__PURE__ */ jsxRuntime.jsxs(ui.TableRow, { children: [
          /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(Identity, { identity: member.identity }) }),
          /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { children: /* @__PURE__ */ jsxRuntime.jsx(IdentityMembership.IdentityMembership, { RoleRenderer: RoleRenderer$1, memberships: member.memberships }) }),
          /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { shrunk: true, children: /* @__PURE__ */ jsxRuntime.jsx(LinkButton.LinkButton, { size: "small", to: editIdentityLink, parameters: { identityId: member.identity.id, projectSlug: project }, children: "Edit roles" }) }),
          /* @__PURE__ */ jsxRuntime.jsx(ui.TableCell, { shrunk: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", intent: "danger", onClick: () => removeMember(member.identity.id), children: "Revoke access" }) })
        ] }, member.identity.id);
      }) }) });
    } });
  }
);
exports.MemberList = MemberList;
//# sourceMappingURL=MemberList.cjs.map
