import{r as o}from"./vendor-CmAScyG3.js";import{m as $}from"./page-easing.ts-qWcoVlrb.js";import{M as N,S as v,D as G,F as C,T as j}from"./page-animation.ts-s8nj4IKz.js";import{f as J,n as y,i as K,s as Q}from"./page-math.ts-ELjSTDm6.js";import{F as n}from"./page-FortuneWheel.ts-CaqHFvhq.js";import{u as r}from"./page-fortuneWheel.ts-BU2wXqek.js";try{let s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},g=new s.Error().stack;g&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[g]="c0cec131-0a08-40f2-9f64-d3cb4db3db50",s._sentryDebugIdIdentifier="sentry-dbid-c0cec131-0a08-40f2-9f64-d3cb4db3db50")}catch{}const V=0,oe=()=>{const s=r(e=>e.sectionList),g=r(e=>e.isAvailable),D=r(e=>e.prizeSection),f=r(e=>e.step),R=r(e=>e.setStep),[I,S]=o.useState(0),t=o.useRef(null),T=o.useRef(0),w=o.useRef(!1),a=o.useRef(null),i=o.useRef(null),b=o.useRef(null);o.useEffect(()=>{b.current=D},[D]);const P=360/Math.max(1,s.length||1),F=(e,c)=>{const l=t.current;l&&(l.style.transition=`transform ${e}ms ${c}`)},O=()=>{const e=t.current;e&&i.current&&(e.removeEventListener("transitionend",i.current),i.current=null),a.current!=null&&(window.clearTimeout(a.current),a.current=null)},p=()=>{O();const e=t.current;e&&(e.style.transition="none")},_=e=>{if(w.current)return;w.current=!0;const c=t.current;!c||(c.style.transition="none",c.getBoundingClientRect(),S(m=>y(m)),requestAnimationFrame(()=>{t.current&&(t.current.style.transition="")}),r.getState().step===n.ERROR)||R(K(e)?n.SUCCESS:n.FAILED)};async function d(){if(!g||f===n.SPIN||!s.length||f===n.ERROR)return;w.current=!1,R(n.SPIN),T.current=performance.now();const e=t.current;if(!e)return;const c=Math.max(N,Math.floor(v*G)),l=C*360,m=I+l;e.style.transition="none",e.getBoundingClientRect(),F(c,"linear"),e.getBoundingClientRect(),S(m);const h=c-(performance.now()-T.current);if(h>0&&await new Promise(u=>{setTimeout(u,h)}),r.getState().step===n.ERROR){p();return}const E=b.current;if(!E){e.style.transition="none",requestAnimationFrame(()=>{t.current&&(t.current.style.transition="")}),r.getState().step!==n.ERROR&&R(n.FAILED);return}const M=J(s,E.id);if(M<0){e.style.transition="none",requestAnimationFrame(()=>{t.current&&(t.current.style.transition="")}),r.getState().step!==n.ERROR&&R(n.FAILED);return}const k=y(m),W=y(V-M*P),B=Q(k,W),L=(j-C)*360+B,z=performance.now()-T.current,A=Math.max(N,v-z),U=$(c,l,A,L),x=()=>{const u=t.current;if(u&&i.current&&(u.removeEventListener("transitionend",i.current),i.current=null),a.current!=null&&(window.clearTimeout(a.current),a.current=null),r.getState().step===n.ERROR){p();return}_(E)};e.addEventListener("transitionend",x,{once:!0}),i.current=x;const q=window.setTimeout(()=>{const u=t.current;if(u&&i.current&&(u.removeEventListener("transitionend",i.current),i.current=null),a.current=null,r.getState().step===n.ERROR){p();return}_(E)},A+120);a.current=q,F(A,U),e.getBoundingClientRect(),S(m+L);const H=()=>{O()};d.cleanup=H}return o.useEffect(()=>()=>{var e;(e=d.cleanup)==null||e.call(d)},[]),o.useEffect(()=>{f===n.ERROR&&p()},[f]),{diskRef:t,angle:I,step:f,spin:d}};export{oe as u};
//# sourceMappingURL=page-useWheelSpin.ts-DuvCtVSh.js.map