"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),r=require("zustand"),s=require("../apis/scopeApis.js"),i=require("./useEnvStore.js"),n=function(e,r){return!!r&&function(e){return e?"string"==typeof e?[e]:[e._id,e.id,e.resourceId,e.resource_id].filter(function(e){return"string"==typeof e&&e.length>0}):[]}(e).includes(r)},t=function(e,r){for(var s,i,t=new Set,a=0,o=e;a<o.length;a++){var u=o[a];if(n(u.resourceId,r))for(var c=0,l=null!==(i=null===(s=u.role)||void 0===s?void 0:s.permissions)&&void 0!==i?i:[];c<l.length;c++){var d=l[c];t.add(d.name)}}return t},a=r.create(function(r,n){return{accessData:[],isLoading:!1,error:null,fetchPermissions:function(i,n){return e.__awaiter(void 0,void 0,void 0,function(){var t,a,o;return e.__generator(this,function(e){switch(e.label){case 0:if(!i)return[2];r({isLoading:!0,error:null}),e.label=1;case 1:return e.trys.push([1,3,,4]),[4,s.appsecApi.get("/users/me",{params:{appId:i,resourceId:n}})];case 2:return t=e.sent(),r({accessData:(null===(o=t.data)||void 0===o?void 0:o.data)||[],isLoading:!1}),[3,4];case 3:return a=e.sent(),console.error("Failed to fetch permissions:",a),r({error:a.message||"Failed to fetch permissions",isLoading:!1}),[3,4];case 4:return[2]}})})},hasPermission:function(e,r){var s,a=n().accessData,o=null===(s=i.default.getState().rbacConfig)||void 0===s?void 0:s.applicationResourceId;if(o&&t(a,o).has(e))return!0;if(r&&t(a,r).has(e))return!0;return!1},hasGlobalPermission:function(e,r){return!!r&&(n().hasApplicationAccess(r)||n().hasPermission(e,r))},hasApplicationAccess:function(e){if(!e)return!1;var r=n().accessData;return t(r,e).has("ilotj.scope.access.application.user.add")},reset:function(){return r({accessData:[],isLoading:!1,error:null})}}});exports.usePermissionsStore=a;
//# sourceMappingURL=usePermissionsStore.js.map
