import n from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/regenerator";import{jsx as e}from"react/jsx-runtime";import{createContext as t,useRef as u,useMemo as i,useContext as c}from"react";var o;!function(n){n.CLOSED="CLOSED",n.OPENNING="OPENNING",n.OPENED="OPENED",n.CLOSING="CLOSING"}(o||(o={}));var a=t(null),s=function(t){var c=t.setIsFullscreenModalMode,s=t.children,l={name:o.CLOSED,currentElementInfo:null},f=u({}),m=i((function(){function e(n){return t.apply(this,arguments)}function t(){return(t=n(r.mark((function n(e){var t,u;return r.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return t=e.transitionFn,u=e.plannedAfterTransitionFinishCb,n.prev=1,n.next=4,t();case 4:n.next=9;break;case 6:n.prev=6,n.t0=n.catch(1),console.error("Transition error: ",n.t0);case 9:u();case 10:case"end":return n.stop()}}),n,null,[[1,6]])})))).apply(this,arguments)}function u(n){var r=n.id;f.current[r]={name:o.OPENED,currentElementInfo:n},f.current[r].currentElementInfo.setIsOpened(!0)}function i(n,r){var t=n.id;f.current[t]={name:o.OPENNING,currentElementInfo:null},e({transitionFn:function(){return c(!0,r)},plannedAfterTransitionFinishCb:function(){u(n)}})}function a(t){var u;f.current[t].name=o.CLOSING,e({transitionFn:(u=n(r.mark((function n(){var e;return r.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(null===(e=f.current[t].currentElementInfo)||void 0===e||e.setIsOpened(!1),f.current[t].currentElementInfo=null,Object.keys(f.current).some((function(n){var r=f.current[n].name;return r===o.OPENNING||r===o.OPENED}))){n.next=4;break}return n.abrupt("return",c(!1));case 4:case"end":return n.stop()}}),n)}))),function(){return u.apply(this,arguments)}),plannedAfterTransitionFinishCb:function(){f.current[t]&&(f.current[t].name=o.CLOSED)}})}return{requestOpen:function(n){var r,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=n.id;switch(null!==(r=f.current)&&void 0!==r&&r[t]||(f.current[t]=l),f.current[n.id].name){case o.CLOSED:i(n,e);break;case o.OPENNING:case o.OPENED:u(n);break;case o.CLOSING:i(n,e)}},requestClose:function(n){var r,e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=n.id;if(null!==(r=f.current)&&void 0!==r&&r[t]||(f.current[t]=l),e)return delete f.current[t],void c(!1);a(t)}}}),[c]);return e(a.Provider,{value:m,children:s})};function l(){return c(a)}export{s as DcFullscreenElemsCoordinatorProvider,l as useDcFullscreenElemsCoordinator};
//# sourceMappingURL=DcFullscreenElemsCoordinatorProvider.js.map
