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