import r from"@babel/runtime/helpers/slicedToArray";import{useState as n,useRef as e,useCallback as t,useEffect as u}from"react";var l=function(l){var c=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=c.thresholdMs,o=void 0===i?50:i,a=c.minDurationMs,f=void 0===a?100:a,m=n(!1),s=r(m,2),v=s[0],d=s[1],T=e(null),h=e(null),p=e(null),D=e(0),b=t((function(){null!==h.current&&(clearTimeout(h.current),h.current=null),null!==p.current&&(clearTimeout(p.current),p.current=null)}),[]);return u((function(){D.current+=1;var r=D.current;if(l)b(),h.current=setTimeout((function(){D.current===r&&(T.current=Date.now(),d(!0))}),o);else if(b(),v){var n=T.current;if(null===n)d(!1);else{var e=Date.now()-n,t=f-e;t<=0?(T.current=null,d(!1)):p.current=setTimeout((function(){D.current===r&&(T.current=null,d(!1))}),t)}}return function(){b()}}),[l,o,f,b,v]),{isLoading:v}};export{l as useDeferredLoading};
//# sourceMappingURL=useDeferredLoading.js.map
