import{Ir as e,Rr as t}from"./index-BKLG6eUi.js";function n(n,r,i={}){let{pauseWhenHidden:a=!0,immediate:o=!1}=i,s=null,c=!1,l=!1;function u(){let e=typeof r==`function`?r():r;return Math.max(1e3,e)}function d(){s&&=(clearTimeout(s),null)}function f(){d(),!c&&(s=setTimeout(()=>{p()},u()))}async function p(){if(!c){if(a&&document.visibilityState===`hidden`){f();return}if(l){f();return}l=!0;try{await n()}finally{l=!1,f()}}}function m(){c||!a||document.visibilityState===`visible`&&p()}return t(()=>{o?p():f(),a&&document.addEventListener(`visibilitychange`,m)}),e(()=>{c=!0,d(),a&&document.removeEventListener(`visibilitychange`,m)}),{refresh:p,stop:()=>{c=!0,d()}}}export{n as t};