import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { Component } from "@contember/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__ */ jsxDEV(Fragment, { children }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/Identity/HasRole.tsx",
    lineNumber: 20,
    columnNumber: 49
  }, globalThis) : 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__ */ jsxDEV(Fragment, { children }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/Identity/HasRole.tsx",
    lineNumber: 26,
    columnNumber: 49
  }, globalThis) : null;
});
const evaluateCondition = (condition, roles) => {
  if (typeof condition === "string") {
    return roles.has(condition);
  }
  return condition(roles);
};
export {
  HasRole
};
//# sourceMappingURL=HasRole.js.map
