var D=u=>{throw TypeError(u)};var B=(u,e,t)=>e.has(u)||D("Cannot "+t);var r=(u,e,t)=>(B(u,e,"read from private field"),t?t.call(u):e.get(u)),p=(u,e,t)=>e.has(u)?D("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(u):e.set(u,t),c=(u,e,t,s)=>(B(u,e,"write to private field"),s?s.call(u,t):e.set(u,t),t),y=(u,e,t)=>(B(u,e,"access private method"),t);import{bJ as G,bK as A,bL as W,bM as X,bN as V,m as Y,bO as Z,bP as $,r as k,bQ as ee,bR as se,bS as te,bT as re,bU as J,bV as ie,bW as ne}from"./index-7T7TTikv.js";function K(u,e){const t=new Set(e);return u.filter(s=>!t.has(s))}function oe(u,e,t){const s=u.slice(0);return s[e]=t,s}var E,b,w,R,d,v,M,q,x,H,h,U,z,_,I,T,j,N,ue=(N=class extends G{constructor(e,t,s){super();p(this,h);p(this,E);p(this,b);p(this,w);p(this,R);p(this,d);p(this,v);p(this,M);p(this,q);p(this,x);p(this,H,[]);c(this,E,e),c(this,R,s),c(this,w,[]),c(this,d,[]),c(this,b,[]),this.setQueries(t)}onSubscribe(){this.listeners.size===1&&r(this,d).forEach(e=>{e.subscribe(t=>{y(this,h,T).call(this,e,t)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,r(this,d).forEach(e=>{e.destroy()})}setQueries(e,t){c(this,w,e),c(this,R,t),A.batch(()=>{const s=r(this,d),i=y(this,h,I).call(this,r(this,w));i.forEach(a=>a.observer.setOptions(a.defaultedQueryOptions));const n=i.map(a=>a.observer),o=n.map(a=>a.getCurrentResult()),l=s.length!==n.length,O=n.some((a,Q)=>a!==s[Q]),C=l||O,P=C?!0:o.some((a,Q)=>{const S=r(this,b)[Q];return!S||!W(a,S)});!C&&!P||(C&&(c(this,H,i),c(this,d,n)),c(this,b,o),this.hasListeners()&&(C&&(K(s,n).forEach(a=>{a.destroy()}),K(n,s).forEach(a=>{a.subscribe(Q=>{y(this,h,T).call(this,a,Q)})})),y(this,h,j).call(this)))})}getCurrentResult(){return r(this,b)}getQueries(){return r(this,d).map(e=>e.getCurrentQuery())}getObservers(){return r(this,d)}getOptimisticResult(e,t){const s=y(this,h,I).call(this,e),i=s.map(o=>o.observer.getOptimisticResult(o.defaultedQueryOptions)),n=s.map(o=>o.defaultedQueryOptions.queryHash);return[i,o=>y(this,h,z).call(this,o??i,t,n),()=>y(this,h,U).call(this,i,s)]}},E=new WeakMap,b=new WeakMap,w=new WeakMap,R=new WeakMap,d=new WeakMap,v=new WeakMap,M=new WeakMap,q=new WeakMap,x=new WeakMap,H=new WeakMap,h=new WeakSet,U=function(e,t){return t.map((s,i)=>{const n=e[i];return s.defaultedQueryOptions.notifyOnChangeProps?n:s.observer.trackResult(n,o=>{t.forEach(l=>{l.observer.trackProp(o)})})})},z=function(e,t,s){if(t){const i=r(this,x),n=s!==void 0&&i!==void 0&&(i.length!==s.length||s.some((o,l)=>o!==i[l]));return(!r(this,v)||r(this,b)!==r(this,q)||n||t!==r(this,M))&&(c(this,M,t),c(this,q,r(this,b)),s!==void 0&&c(this,x,s),c(this,v,X(r(this,v),t(e)))),r(this,v)}return e},_=function(){var e;return((e=r(this,R))==null?void 0:e.combine)!==void 0&&r(this,d).some((t,s)=>{var i;return t.options.suspense&&((i=r(this,b)[s])==null?void 0:i.data)===void 0})},I=function(e){const t=new Map;r(this,d).forEach(i=>{const n=i.options.queryHash;if(!n)return;const o=t.get(n);o?o.push(i):t.set(n,[i])});const s=[];return e.forEach(i=>{var O;const n=r(this,E).defaultQueryOptions(i),l=((O=t.get(n.queryHash))==null?void 0:O.shift())??new V(r(this,E),n);s.push({defaultedQueryOptions:n,observer:l})}),s},T=function(e,t){const s=r(this,d).indexOf(e);s!==-1&&(c(this,b,oe(r(this,b),s,t)),y(this,h,j).call(this))},j=function(){var e;if(this.hasListeners()){const t=y(this,h,U).call(this,r(this,b),r(this,H)),s=y(this,h,_).call(this),i=r(this,v),n=s?i:y(this,h,z).call(this,t,(e=r(this,R))==null?void 0:e.combine);(s||i!==n)&&A.batch(()=>{this.listeners.forEach(o=>{o(r(this,b))})})}},N);function ce({queries:u,...e},t){const s=Y(),i=Z(),n=$(),o=k.useMemo(()=>u.map(f=>{const g=s.defaultQueryOptions(f);return g._optimisticResults=i?"isRestoring":"optimistic",g}),[u,s,i]);o.forEach(f=>{ee(f);const g=s.getQueryCache().get(f.queryHash);se(f,n,g)}),te(n);const[l]=k.useState(()=>new ue(s,o,e)),[O,C,P]=l.getOptimisticResult(o,e.combine),a=!i&&e.subscribed!==!1;k.useSyncExternalStore(k.useCallback(f=>a?l.subscribe(A.batchCalls(f)):re,[l,a]),()=>l.getCurrentResult(),()=>l.getCurrentResult()),k.useEffect(()=>{l.setQueries(o,e)},[o,e,l]);const S=O.some((f,g)=>J(o[g],f))?O.flatMap((f,g)=>{const m=o[g];if(m&&J(m,f)){const F=new V(s,m);return ie(m,F,n)}return[]}):[];if(S.length>0)throw Promise.all(S);const L=O.find((f,g)=>{const m=o[g];return m&&ne({result:f,errorResetBoundary:n,throwOnError:m.throwOnError,query:s.getQueryCache().get(m.queryHash),suspense:m.suspense})});if(L!=null&&L.error)throw L.error;return C(P())}export{ce as u};
