import{__assign as n,__awaiter as r,__generator as e}from'./../../../../../ext-esm/tslib/tslib.es6.js';import{jsx as t}from"react/jsx-runtime";import{createContext as i,useRef as u,useMemo as o,useContext as c}from"react";var s;!function(n){n.CLOSED="CLOSED",n.OPENNING="OPENNING",n.OPENED="OPENED",n.CLOSING="CLOSING"}(s||(s={}));var a=i(null),l=function(i){var c=i.setIsFullscreenModalMode,l=i.children,f={name:s.CLOSED,currentElementInfo:null},d=u({}),E=o((function(){function n(n){var t=n.transitionFn,i=n.plannedAfterTransitionFinishCb;return r(this,void 0,void 0,(function(){var n;return e(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t()];case 1:return r.sent(),[3,3];case 2:return n=r.sent(),console.error("Transition error: ",n),[3,3];case 3:return i(),[2]}}))}))}function t(n){var r=n.id;d.current[r]={name:s.OPENED,currentElementInfo:n},d.current[r].currentElementInfo.setIsOpened(!0)}function i(r){var e=r.id;d.current[e]={name:s.OPENNING,currentElementInfo:null},n({transitionFn:function(){return c(!0)},plannedAfterTransitionFinishCb:function(){t(r)}})}function u(t){var i=this;d.current[t].name=s.CLOSING,n({transitionFn:function(){return r(i,void 0,void 0,(function(){var n;return e(this,(function(r){return null===(n=d.current[t].currentElementInfo)||void 0===n||n.setIsOpened(!1),d.current[t].currentElementInfo=null,Object.keys(d.current).some((function(n){var r=d.current[n].name;return r===s.OPENNING||r===s.OPENED}))?[2]:[2,c(!1)]}))}))},plannedAfterTransitionFinishCb:function(){d.current[t]&&(d.current[t].name=s.CLOSED)}})}return{requestOpen:function(n){var r,e=n.id;switch((null===(r=d.current)||void 0===r?void 0:r[e])||(d.current[e]=f),d.current[n.id].name){case s.CLOSED:i(n);break;case s.OPENNING:case s.OPENED:t(n);break;case s.CLOSING:i(n)}},requestClose:function(n,r){var e;void 0===r&&(r=!1);var t=n.id;if((null===(e=d.current)||void 0===e?void 0:e[t])||(d.current[t]=f),r)return delete d.current[t],c(!1);u(t)}}}),[c]);return t(a.Provider,n({value:E},{children:l}))};function f(){return c(a)}export{l as DcFullscreenElemsCoordinatorProvider,f as useDcFullscreenElemsCoordinator};
