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