import{E as P,ay as b,az as E,W as m,s as p}from"./Bxv1kRJt.js";function H(n,t){const r=t/n*100;return 2/Math.PI*100*Math.atan(r/50)}function S(n={}){const{duration:t=2e3,throttle:r=200,hideDelay:k=500,resetDelay:x=400}=n,y=n.estimatedProgress||H,u=P(),i=m(0),s=m(!1),d=m(!1);let f=!1,g,h,v,T;const _=(e={})=>{D(),d.value=!1,I(0,e)};function I(e=0,o={}){if(u.isHydrating)return;if(e>=100)return l({force:o.force});c(),i.value=e<0?0:e;const a=o.force?0:r;a?h=setTimeout(()=>{s.value=!0,A()},a):(s.value=!0,A())}function F(){v=setTimeout(()=>{s.value=!1,T=setTimeout(()=>{i.value=0},x)},k)}function l(e={}){i.value=100,f=!0,c(),D(),e.error&&(d.value=!0),e.force?(i.value=0,s.value=!1):F()}function D(){clearTimeout(v),clearTimeout(T)}function c(){clearTimeout(h),cancelAnimationFrame(g)}function A(){f=!1;let e;function o(a){if(f)return;e??=a;const M=a-e;i.value=Math.max(0,Math.min(100,y(t,M))),g=requestAnimationFrame(o)}g=requestAnimationFrame(o)}let L=()=>{};{const e=u.hook("page:loading:start",()=>{_()}),o=u.hook("page:loading:end",()=>{l()}),a=u.hook("vue:error",()=>l());L=()=>{a(),e(),o(),c()}}return{_cleanup:L,progress:p(()=>i.value),isLoading:p(()=>s.value),error:p(()=>d.value),start:_,set:I,finish:l,clear:c}}function w(n={}){const t=P(),r=t._loadingIndicator||=S(n);return b()&&(t._loadingIndicatorDeps||=0,t._loadingIndicatorDeps++,E(()=>{t._loadingIndicatorDeps--,t._loadingIndicatorDeps===0&&(r._cleanup(),delete t._loadingIndicator)})),r}export{w as u};
