import{s as o}from"./chunk-LvLJmgfZ.js";import{t as m}from"./react-Bj1aDYRI.js";import{t as v}from"./useEventListener-C0195JsF.js";var e=o(m(),1);function b(a,f){let{delayMs:r,whenVisible:n,disabled:l=!1,skipIfRunning:c=!1}=f,t=(0,e.useRef)(void 0),s=(0,e.useRef)(!1);(0,e.useEffect)(()=>{t.current=a},[a]);let u=(0,e.useCallback)(async()=>{var i;if(!(s.current&&c)){s.current=!0;try{await((i=t.current)==null?void 0:i.call(t))}finally{s.current=!1}}},[c]);return(0,e.useEffect)(()=>{if(r===null||l)return;let i=setInterval(()=>{n&&document.visibilityState!=="visible"||u()},r);return()=>clearInterval(i)},[r,n,l,u]),v(document,"visibilitychange",()=>{document.visibilityState==="visible"&&n&&!l&&u()}),null}export{b as t};
