import{a as p}from"./chunk-QMGIS6GS-CBZUm-7V.js";import{c as l}from"./OptionalPortal-2PgDA1pn.js";function m(t){let e=t,n=!1;const i=new Set;return{getState(){return e},updateState(o){e=typeof o=="function"?o(e):o},setState(o){this.updateState(o),i.forEach(g=>g(e))},initialize(o){n||(e=o,n=!0)},subscribe(o){return i.add(o),()=>i.delete(o)}}}function v(t){return p.useSyncExternalStore(t.subscribe,()=>t.getState(),()=>t.getState())}function a(t){let e=.5;return t>=0&&t<=20?e=10:t>=20&&t<=50?e=4:t>=50&&t<=80?e=2:t>=80&&t<=99?e=1:t>=99&&t<=100&&(e=0),t+e}const d=()=>m({mounted:!1,progress:0,interval:0,step:1,stepInterval:100,timeouts:[]}),h=t=>v(t);function s(t,e){const n=e.getState();e.setState({...n,...t(e.getState())})}function f(t){s(e=>({progress:Math.max(e.progress-e.step,0)}),t)}function N(t,e){s(()=>({progress:l(t,0,100),mounted:!0}),e)}function r(t){s(e=>(window.clearInterval(e.interval),e.timeouts.forEach(n=>window.clearTimeout(n)),{timeouts:[]}),t)}function w(t){r(t),s(e=>{const n=window.setTimeout(()=>{s(()=>({mounted:!1}),t)},50),i=window.setTimeout(()=>{s(()=>({progress:0}),t)},e.stepInterval+50);return{progress:100,timeouts:[n,i]}},t)}function S(t){s(e=>({progress:a(e.progress),mounted:!0}),t),s(e=>(window.clearInterval(e.interval),{interval:window.setInterval(()=>{s(i=>({progress:a(i.progress),mounted:!0}),t)},e.stepInterval),mounted:!0}),t)}function c(t){s(e=>(window.clearInterval(e.interval),{interval:-1}),t)}function u(t){r(t),c(t),s(()=>({progress:0,mounted:!1}),t)}function A(t){s(e=>{const n=Math.min(e.progress+e.step,100),i=n!==100&&n!==0;if(!i){const o=window.setTimeout(()=>u(t),e.stepInterval+50);return{progress:n,mounted:i,timeouts:[...e.timeouts,o]}}return{progress:n,mounted:i}},t)}function I(){const t=d();return[t,{start:()=>S(t),stop:()=>c(t),reset:()=>u(t),set:n=>N(n,t),increment:()=>A(t),decrement:()=>f(t),complete:()=>w(t),cleanup:()=>r(t)}]}const[E,P]=I(),{start:b,stop:M,reset:y,set:z,increment:V,decrement:j,complete:q,cleanup:B}=P;export{E as a,P as n,u as r,h as u};
