import{G as g,H as p,y as d}from"./index-BKKvzUDD.js";function T(m,a=5e3,v={}){const{immediate:h=!0,pauseWhenHidden:o=!0,onError:r}=v,e=d(!1),n=d(!1);let t=null;function i(){t&&(clearTimeout(t),t=null)}function s(){if(i(),!e.value||o&&document.hidden)return;const l=typeof a=="function"?a():a;t=setTimeout(()=>void u(),Math.max(0,l))}async function u(){if(i(),!(!e.value||n.value)&&!(o&&document.hidden)){n.value=!0;try{await m()}catch(l){r==null||r(l)}finally{n.value=!1,s()}}}function c(){e.value=!1,i()}function y(){e.value||(e.value=!0,h?u():s())}function f(){!o||!e.value||(document.hidden?i():u())}return g(()=>document.addEventListener("visibilitychange",f)),p(()=>{c(),document.removeEventListener("visibilitychange",f)}),{start:y,stop:c,run:u,isActive:e,isRunning:n}}export{T as u};
