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