var ut=e=>{throw TypeError(e)};var G=(e,t,i)=>t.has(e)||ut("Cannot "+i);var s=(e,t,i)=>(G(e,t,"read from private field"),i?i.call(e):t.get(e)),d=(e,t,i)=>t.has(e)?ut("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),o=(e,t,i,r)=>(G(e,t,"write to private field"),r?r.call(e,i):t.set(e,i),i),l=(e,t,i)=>(G(e,t,"access private method"),i);import{a4 as Ot,a5 as lt,a6 as S,a7 as J,a8 as W,a9 as St,aa as X,ab as ft,ac as Et,ad as It,ae as Qt,af as dt,ag as yt,K as xt}from"./index-CmAiVN5e.js";import{r as Q}from"./vendor-animations-CsoOZIH8.js";var R,a,z,g,U,L,w,O,N,j,k,D,P,T,B,n,H,Y,Z,tt,et,st,it,rt,mt,Rt,wt=(Rt=class extends Ot{constructor(t,i){super();d(this,n);d(this,R);d(this,a);d(this,z);d(this,g);d(this,U);d(this,L);d(this,w);d(this,O);d(this,N);d(this,j);d(this,k);d(this,D);d(this,P);d(this,T);d(this,B,new Set);this.options=i,o(this,R,t),o(this,O,null),o(this,w,lt()),this.options.experimental_prefetchInRender||s(this,w).reject(new Error("experimental_prefetchInRender feature flag is not enabled")),this.bindMethods(),this.setOptions(i)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(s(this,a).addObserver(this),pt(s(this,a),this.options)?l(this,n,H).call(this):this.updateResult(),l(this,n,et).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return at(s(this,a),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return at(s(this,a),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,l(this,n,st).call(this),l(this,n,it).call(this),s(this,a).removeObserver(this)}setOptions(t,i){const r=this.options,f=s(this,a);if(this.options=s(this,R).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof S(this.options.enabled,s(this,a))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");l(this,n,rt).call(this),s(this,a).setOptions(this.options),r._defaulted&&!J(this.options,r)&&s(this,R).getQueryCache().notify({type:"observerOptionsUpdated",query:s(this,a),observer:this});const c=this.hasListeners();c&&bt(s(this,a),f,this.options,r)&&l(this,n,H).call(this),this.updateResult(i),c&&(s(this,a)!==f||S(this.options.enabled,s(this,a))!==S(r.enabled,s(this,a))||W(this.options.staleTime,s(this,a))!==W(r.staleTime,s(this,a)))&&l(this,n,Y).call(this);const h=l(this,n,Z).call(this);c&&(s(this,a)!==f||S(this.options.enabled,s(this,a))!==S(r.enabled,s(this,a))||h!==s(this,T))&&l(this,n,tt).call(this,h)}getOptimisticResult(t){const i=s(this,R).getQueryCache().build(s(this,R),t),r=this.createResult(i,t);return Ft(this,r)&&(o(this,g,r),o(this,L,this.options),o(this,U,s(this,a).state)),r}getCurrentResult(){return s(this,g)}trackResult(t,i){const r={};return Object.keys(t).forEach(f=>{Object.defineProperty(r,f,{configurable:!1,enumerable:!0,get:()=>(this.trackProp(f),i==null||i(f),t[f])})}),r}trackProp(t){s(this,B).add(t)}getCurrentQuery(){return s(this,a)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const i=s(this,R).defaultQueryOptions(t),r=s(this,R).getQueryCache().build(s(this,R),i);return r.fetch().then(()=>this.createResult(r,i))}fetch(t){return l(this,n,H).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),s(this,g)))}createResult(t,i){var ct;const r=s(this,a),f=this.options,c=s(this,g),h=s(this,U),E=s(this,L),y=t!==r?t.state:s(this,z),{state:m}=t;let u={...m},F=!1,v;if(i._optimisticResults){const b=this.hasListeners(),_=!b&&pt(t,i),M=b&&bt(t,r,i,f);(_||M)&&(u={...u,...Qt(m.data,t.options)}),i._optimisticResults==="isRestoring"&&(u.fetchStatus="idle")}let{error:A,errorUpdatedAt:x,status:I}=u;if(i.select&&u.data!==void 0)if(c&&u.data===(h==null?void 0:h.data)&&i.select===s(this,N))v=s(this,j);else try{o(this,N,i.select),v=i.select(u.data),v=dt(c==null?void 0:c.data,v,i),o(this,j,v),o(this,O,null)}catch(b){o(this,O,b)}else v=u.data;if(i.placeholderData!==void 0&&v===void 0&&I==="pending"){let b;if(c!=null&&c.isPlaceholderData&&i.placeholderData===(E==null?void 0:E.placeholderData))b=c.data;else if(b=typeof i.placeholderData=="function"?i.placeholderData((ct=s(this,k))==null?void 0:ct.state.data,s(this,k)):i.placeholderData,i.select&&b!==void 0)try{b=i.select(b),o(this,O,null)}catch(_){o(this,O,_)}b!==void 0&&(I="success",v=dt(c==null?void 0:c.data,b,i),F=!0)}s(this,O)&&(A=s(this,O),v=s(this,j),x=Date.now(),I="error");const K=u.fetchStatus==="fetching",$=I==="pending",q=I==="error",ht=$&&K,ot=v!==void 0,C={status:I,fetchStatus:u.fetchStatus,isPending:$,isSuccess:I==="success",isError:q,isInitialLoading:ht,isLoading:ht,data:v,dataUpdatedAt:u.dataUpdatedAt,error:A,errorUpdatedAt:x,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:u.dataUpdateCount>0||u.errorUpdateCount>0,isFetchedAfterMount:u.dataUpdateCount>y.dataUpdateCount||u.errorUpdateCount>y.errorUpdateCount,isFetching:K,isRefetching:K&&!$,isLoadingError:q&&!ot,isPaused:u.fetchStatus==="paused",isPlaceholderData:F,isRefetchError:q&&ot,isStale:nt(t,i),refetch:this.refetch,promise:s(this,w)};if(this.options.experimental_prefetchInRender){const b=V=>{C.status==="error"?V.reject(C.error):C.data!==void 0&&V.resolve(C.data)},_=()=>{const V=o(this,w,C.promise=lt());b(V)},M=s(this,w);switch(M.status){case"pending":t.queryHash===r.queryHash&&b(M);break;case"fulfilled":(C.status==="error"||C.data!==M.value)&&_();break;case"rejected":(C.status!=="error"||C.error!==M.reason)&&_();break}}return C}updateResult(t){const i=s(this,g),r=this.createResult(s(this,a),this.options);if(o(this,U,s(this,a).state),o(this,L,this.options),s(this,U).data!==void 0&&o(this,k,s(this,a)),J(r,i))return;o(this,g,r);const f={},c=()=>{if(!i)return!0;const{notifyOnChangeProps:h}=this.options,E=typeof h=="function"?h():h;if(E==="all"||!E&&!s(this,B).size)return!0;const p=new Set(E??s(this,B));return this.options.throwOnError&&p.add("error"),Object.keys(s(this,g)).some(y=>{const m=y;return s(this,g)[m]!==i[m]&&p.has(m)})};(t==null?void 0:t.listeners)!==!1&&c()&&(f.listeners=!0),l(this,n,mt).call(this,{...f,...t})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&l(this,n,et).call(this)}},R=new WeakMap,a=new WeakMap,z=new WeakMap,g=new WeakMap,U=new WeakMap,L=new WeakMap,w=new WeakMap,O=new WeakMap,N=new WeakMap,j=new WeakMap,k=new WeakMap,D=new WeakMap,P=new WeakMap,T=new WeakMap,B=new WeakMap,n=new WeakSet,H=function(t){l(this,n,rt).call(this);let i=s(this,a).fetch(this.options,t);return t!=null&&t.throwOnError||(i=i.catch(St)),i},Y=function(){l(this,n,st).call(this);const t=W(this.options.staleTime,s(this,a));if(X||s(this,g).isStale||!ft(t))return;const r=Et(s(this,g).dataUpdatedAt,t)+1;o(this,D,setTimeout(()=>{s(this,g).isStale||this.updateResult()},r))},Z=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(s(this,a)):this.options.refetchInterval)??!1},tt=function(t){l(this,n,it).call(this),o(this,T,t),!(X||S(this.options.enabled,s(this,a))===!1||!ft(s(this,T))||s(this,T)===0)&&o(this,P,setInterval(()=>{(this.options.refetchIntervalInBackground||It.isFocused())&&l(this,n,H).call(this)},s(this,T)))},et=function(){l(this,n,Y).call(this),l(this,n,tt).call(this,l(this,n,Z).call(this))},st=function(){s(this,D)&&(clearTimeout(s(this,D)),o(this,D,void 0))},it=function(){s(this,P)&&(clearInterval(s(this,P)),o(this,P,void 0))},rt=function(){const t=s(this,R).getQueryCache().build(s(this,R),this.options);if(t===s(this,a))return;const i=s(this,a);o(this,a,t),o(this,z,t.state),this.hasListeners()&&(i==null||i.removeObserver(this),t.addObserver(this))},mt=function(t){yt.batch(()=>{t.listeners&&this.listeners.forEach(i=>{i(s(this,g))}),s(this,R).getQueryCache().notify({query:s(this,a),type:"observerResultsUpdated"})})},Rt);function Tt(e,t){return S(t.enabled,e)!==!1&&e.state.data===void 0&&!(e.state.status==="error"&&t.retryOnMount===!1)}function pt(e,t){return Tt(e,t)||e.state.data!==void 0&&at(e,t,t.refetchOnMount)}function at(e,t,i){if(S(t.enabled,e)!==!1){const r=typeof i=="function"?i(e):i;return r==="always"||r!==!1&&nt(e,t)}return!1}function bt(e,t,i,r){return(e!==t||S(r.enabled,e)===!1)&&(!i.suspense||e.state.status!=="error")&&nt(e,i)}function nt(e,t){return S(t.enabled,e)!==!1&&e.isStaleByTime(W(t.staleTime,e))}function Ft(e,t){return!J(e.getCurrentResult(),t)}var Ct=Q.createContext(!1),Ut=()=>Q.useContext(Ct);Ct.Provider;function Dt(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Pt=Q.createContext(Dt()),_t=()=>Q.useContext(Pt);function Mt(e,t){return typeof e=="function"?e(...t):!!e}function gt(){}var Lt=(e,t)=>{(e.suspense||e.throwOnError||e.experimental_prefetchInRender)&&(t.isReset()||(e.retryOnMount=!1))},jt=e=>{Q.useEffect(()=>{e.clearReset()},[e])},kt=({result:e,errorResetBoundary:t,throwOnError:i,query:r})=>e.isError&&!t.isReset()&&!e.isFetching&&r&&Mt(i,[e.error,r]),Bt=e=>{e.suspense&&(e.staleTime===void 0&&(e.staleTime=1e3),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3)))},At=(e,t)=>e.isLoading&&e.isFetching&&!t,Ht=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,vt=(e,t,i)=>t.fetchOptimistic(e).catch(()=>{i.clearReset()});function zt(e,t,i){var m,u,F,v,A;const r=xt(),f=Ut(),c=_t(),h=r.defaultQueryOptions(e);(u=(m=r.getDefaultOptions().queries)==null?void 0:m._experimental_beforeQuery)==null||u.call(m,h),h._optimisticResults=f?"isRestoring":"optimistic",Bt(h),Lt(h,c),jt(c);const E=!r.getQueryCache().get(h.queryHash),[p]=Q.useState(()=>new t(r,h)),y=p.getOptimisticResult(h);if(Q.useSyncExternalStore(Q.useCallback(x=>{const I=f?gt:p.subscribe(yt.batchCalls(x));return p.updateResult(),I},[p,f]),()=>p.getCurrentResult(),()=>p.getCurrentResult()),Q.useEffect(()=>{p.setOptions(h,{listeners:!1})},[h,p]),Ht(h,y))throw vt(h,p,c);if(kt({result:y,errorResetBoundary:c,throwOnError:h.throwOnError,query:r.getQueryCache().get(h.queryHash)}))throw y.error;if((v=(F=r.getDefaultOptions().queries)==null?void 0:F._experimental_afterQuery)==null||v.call(F,h,y),h.experimental_prefetchInRender&&!X&&At(y,f)){const x=E?vt(h,p,c):(A=r.getQueryCache().get(h.queryHash))==null?void 0:A.promise;x==null||x.catch(gt).finally(()=>{p.updateResult()})}return h.notifyOnChangeProps?y:p.trackResult(y)}function $t(e,t){return zt(e,wt)}export{$t as u};