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