"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),r=require("react");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=u(e);exports.useDeferredLoading=function(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=u.thresholdMs,l=void 0===t?50:t,c=u.minDurationMs,i=void 0===c?100:c,o=r.useState(!1),a=n.default(o,2),s=a[0],f=a[1],d=r.useRef(null),v=r.useRef(null),m=r.useRef(null),b=r.useRef(0),p=r.useCallback((function(){null!==v.current&&(clearTimeout(v.current),v.current=null),null!==m.current&&(clearTimeout(m.current),m.current=null)}),[]);return r.useEffect((function(){b.current+=1;var r=b.current;if(e)p(),v.current=setTimeout((function(){b.current===r&&(d.current=Date.now(),f(!0))}),l);else if(p(),s){var u=d.current;if(null===u)f(!1);else{var n=Date.now()-u,t=i-n;t<=0?(d.current=null,f(!1)):m.current=setTimeout((function(){b.current===r&&(d.current=null,f(!1))}),t)}}return function(){p()}}),[e,l,i,p,s]),{isLoading:s}};
//# sourceMappingURL=useDeferredLoading.js.map
