import { jsx, Fragment } from "react/jsx-runtime";
import { Component } from "@contember/react-binding";
import { identityEnvironmentExtension } from "./IdentityEnvironmentExtension.js";
import { useProjectUserRoles } from "../../acl/useProjectUserRoles.js";
import { projectEnvironmentExtension } from "../Project/ProjectEnvironmentExtension.js";
const HasRole = Component(({ children, role }) => {
  const projectRoles = useProjectUserRoles();
  return evaluateCondition(role, projectRoles) ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
}, ({ children, role }, env) => {
  const identity = env.getExtension(identityEnvironmentExtension).identity;
  const project = env.getExtension(projectEnvironmentExtension).slug;
  const projectRoles = new Set(identity?.projects.find((it) => it.slug === project)?.roles ?? []);
  return evaluateCondition(role, projectRoles) ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
});
const evaluateCondition = (condition, roles) => {
  if (typeof condition === "string") {
    return roles.has(condition);
  }
  return condition(roles);
};
export {
  HasRole
};
//# sourceMappingURL=HasRole.js.map
