import{d as M,p as $}from"./useEvent-D91BmmQi.js";import{t as g}from"./compiler-runtime-B3qBwwSJ.js";import{g as m}from"./useEventListener-C0195JsF.js";var k=g();function E(u,d){return{reducer:(n,t)=>(n||(n=u()),t.type in d?d[t.type](n,t.payload):(m.error(`Action type ${t.type} is not defined in reducers.`),n)),createActions:n=>{let t={};for(let p in d)t[p]=s=>{n({type:p,payload:s})};return t}}}function x(u,d,n){let t=[...n??[]],p=o=>{t.push(o)},{reducer:s,createActions:l}=E(u,d),A=(o,r)=>{try{let a=s(o,r);for(let e of t)try{e(o,a,r)}catch(i){m.error(`Error in middleware for action ${r.type}:`,i)}return a}catch(a){return m.error(`Error in reducer for action ${r.type}:`,a),o}},h=$(u()),f=new WeakMap;function w(o){let r=(0,k.c)(4),a=o===void 0?{}:o,e=M(h);if(a.skipMiddleware===!0){let c;return r[0]===e?c=r[1]:(c=l(y=>{e(v=>s(v,y))}),r[0]=e,r[1]=c),c}f.has(e)||f.set(e,l(c=>{e(y=>A(y,c))}));let i;return r[2]===e?i=r[3]:(i=f.get(e),r[2]=e,r[3]=i),i}return{reducer:A,addMiddleware:p,createActions:l,valueAtom:h,useActions:w}}export{x as t};
