"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const reactBinding = require("@contember/react-binding");
const IdentityEnvironmentExtension = require("./IdentityEnvironmentExtension.cjs");
const useProjectUserRoles = require("../../acl/useProjectUserRoles.cjs");
const ProjectEnvironmentExtension = require("../Project/ProjectEnvironmentExtension.cjs");
const HasRole = reactBinding.Component(({ children, role }) => {
  const projectRoles = useProjectUserRoles.useProjectUserRoles();
  return evaluateCondition(role, projectRoles) ? /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/Identity/HasRole.tsx",
    lineNumber: 20,
    columnNumber: 49
  }, void 0) : null;
}, ({ children, role }, env) => {
  const identity = env.getExtension(IdentityEnvironmentExtension.identityEnvironmentExtension).identity;
  const project = env.getExtension(ProjectEnvironmentExtension.projectEnvironmentExtension).slug;
  const projectRoles = new Set(identity?.projects.find((it) => it.slug === project)?.roles ?? []);
  return evaluateCondition(role, projectRoles) ? /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/components/Identity/HasRole.tsx",
    lineNumber: 26,
    columnNumber: 49
  }, void 0) : null;
});
const evaluateCondition = (condition, roles) => {
  if (typeof condition === "string") {
    return roles.has(condition);
  }
  return condition(roles);
};
exports.HasRole = HasRole;
//# sourceMappingURL=HasRole.cjs.map
