import { memo, createElement, Fragment, useCallback } from "react";
import { useProjectSlug, useCurrentContentGraphQlClient } from "@contember/react-client";
import { LayoutPage } from "@contember/ui";
import { MemberList } from "../member/MemberList.js";
import { LinkButton } from "../../../routing/binding/LinkButton.js";
const UsersList = memo(({ createUserEditLink, ...props }) => /* @__PURE__ */ createElement(MemberList, {
  ...props,
  createEditIdentityLink: createUserEditLink,
  memberType: "PERSON",
  Identity: ({ identity }) => /* @__PURE__ */ createElement(Fragment, null, identity.person ? identity.person.email : "?")
}));
const UsersManagement = (props) => {
  const project = useProjectSlug();
  const contentClient = useCurrentContentGraphQlClient();
  const roleRendererFactory = useCallback(async () => {
    const rolesData = await contentClient.sendRequest(props.rolesDataQuery);
    return ({ role, variables }) => {
      const Renderer = props.roleRenderers[role];
      if (!Renderer) {
        return /* @__PURE__ */ createElement(Fragment, null, "Unknown role ", role);
      }
      return /* @__PURE__ */ createElement(Renderer, {
        rolesData,
        variables
      });
    };
  }, [contentClient, props.roleRenderers, props.rolesDataQuery]);
  if (project) {
    return /* @__PURE__ */ createElement(LayoutPage, {
      actions: /* @__PURE__ */ createElement(LinkButton, {
        to: "tenantInviteUser"
      }, "Add a user"),
      title: "Users in project"
    }, /* @__PURE__ */ createElement(UsersList, {
      project,
      createRoleRenderer: roleRendererFactory,
      createUserEditLink: (id) => ({ pageName: "tenantEditUser", parameters: { id } })
    }));
  }
  return null;
};
export { UsersList, UsersManagement };
//# sourceMappingURL=UsersList.js.map
