import r from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/slicedToArray";import t from"@babel/runtime/helpers/asyncToGenerator";import n from"@babel/runtime/regenerator";import{useState as o,useRef as i}from"react";import{parsePermission as c}from"./utils.js";import{getPermissionCheck as u}from"../clients/jsonApi/index.js";function s(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),t.push.apply(t,n)}return t}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}function p(r){return f.apply(this,arguments)}function f(){return(f=t(n.mark((function r(e){return n.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,u(e);case 3:return r.abrupt("return",r.sent);case 6:return r.prev=6,r.t0=r.catch(0),console.error(r.t0),r.abrupt("return",{active:!1});case 10:case"end":return r.stop()}}),r,null,[[0,6]])})))).apply(this,arguments)}function l(){var r=o({}),u=e(r,2),s=u[0],f=u[1],l=i(new Set);function m(){return(m=t(n.mark((function r(e){var t,o;return n.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if((t=e.filter((function(r){return!(r in s)&&!l.current.has(r)}))).length){r.next=3;break}return r.abrupt("return");case 3:return r.next=5,Promise.all(t.map((function(r){return l.current.add(r),p(c(r))})));case 5:o=r.sent,f((function(r){var e=a({},r);return t.forEach((function(r,t){l.current.delete(r),e[r]=a({loading:!1},o[t])})),e}));case 7:case"end":return r.stop()}}),r)})))).apply(this,arguments)}return window[Symbol.for("resetPermissionsCache")]=function(){return f({})},{permissions:s,fetchPermissions:function(r){return m.apply(this,arguments)}}}export{l as default};
