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)),f=(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{S as Ct,a4 as lt,a5 as S,s as J,a6 as W,a7 as Ot,a8 as X,a9 as dt,aa as St,ab as Et,ac as Qt,ad as ft,n as yt,r as I,e as It}from"./index-CdG8kR3s.js";var y,a,z,v,U,L,x,O,N,j,k,D,P,T,B,n,H,Y,Z,tt,et,st,it,rt,Rt,gt,wt=(gt=class extends Ct{constructor(t,i){super();f(this,n);f(this,y);f(this,a);f(this,z);f(this,v);f(this,U);f(this,L);f(this,x);f(this,O);f(this,N);f(this,j);f(this,k);f(this,D);f(this,P);f(this,T);f(this,B,new Set);this.options=i,o(this,y,t),o(this,O,null),o(this,x,lt()),this.options.experimental_prefetchInRender||s(this,x).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,d=s(this,a);if(this.options=s(this,y).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,y).getQueryCache().notify({type:"observerOptionsUpdated",query:s(this,a),observer:this});const c=this.hasListeners();c&&bt(s(this,a),d,this.options,r)&&l(this,n,H).call(this),this.updateResult(i),c&&(s(this,a)!==d||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)!==d||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,y).getQueryCache().build(s(this,y),t),r=this.createResult(i,t);return Tt(this,r)&&(o(this,v,r),o(this,L,this.options),o(this,U,s(this,a).state)),r}getCurrentResult(){return s(this,v)}trackResult(t,i){const r={};return Object.keys(t).forEach(d=>{Object.defineProperty(r,d,{configurable:!1,enumerable:!0,get:()=>(this.trackProp(d),i==null||i(d),t[d])})}),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,y).defaultQueryOptions(t),r=s(this,y).getQueryCache().build(s(this,y),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,v)))}createResult(t,i){var ct;const r=s(this,a),d=this.options,c=s(this,v),h=s(this,U),E=s(this,L),R=t!==r?t.state:s(this,z),{state:m}=t;let u={...m},F=!1,g;if(i._optimisticResults){const b=this.hasListeners(),M=!b&&pt(t,i),_=b&&bt(t,r,i,d);(M||_)&&(u={...u,...Qt(m.data,t.options)}),i._optimisticResults==="isRestoring"&&(u.fetchStatus="idle")}let{error:A,errorUpdatedAt:w,status:Q}=u;if(i.select&&u.data!==void 0)if(c&&u.data===(h==null?void 0:h.data)&&i.select===s(this,N))g=s(this,j);else try{o(this,N,i.select),g=i.select(u.data),g=ft(c==null?void 0:c.data,g,i),o(this,j,g),o(this,O,null)}catch(b){o(this,O,b)}else g=u.data;if(i.placeholderData!==void 0&&g===void 0&&Q==="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(M){o(this,O,M)}b!==void 0&&(Q="success",g=ft(c==null?void 0:c.data,b,i),F=!0)}s(this,O)&&(A=s(this,O),g=s(this,j),w=Date.now(),Q="error");const K=u.fetchStatus==="fetching",$=Q==="pending",q=Q==="error",ht=$&&K,ot=g!==void 0,C={status:Q,fetchStatus:u.fetchStatus,isPending:$,isSuccess:Q==="success",isError:q,isInitialLoading:ht,isLoading:ht,data:g,dataUpdatedAt:u.dataUpdatedAt,error:A,errorUpdatedAt:w,failureCount:u.fetchFailureCount,failureReason:u.fetchFailureReason,errorUpdateCount:u.errorUpdateCount,isFetched:u.dataUpdateCount>0||u.errorUpdateCount>0,isFetchedAfterMount:u.dataUpdateCount>R.dataUpdateCount||u.errorUpdateCount>R.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,x)};if(this.options.experimental_prefetchInRender){const b=V=>{C.status==="error"?V.reject(C.error):C.data!==void 0&&V.resolve(C.data)},M=()=>{const V=o(this,x,C.promise=lt());b(V)},_=s(this,x);switch(_.status){case"pending":t.queryHash===r.queryHash&&b(_);break;case"fulfilled":(C.status==="error"||C.data!==_.value)&&M();break;case"rejected":(C.status!=="error"||C.error!==_.reason)&&M();break}}return C}updateResult(t){const i=s(this,v),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,v,r);const d={},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,v)).some(R=>{const m=R;return s(this,v)[m]!==i[m]&&p.has(m)})};(t==null?void 0:t.listeners)!==!1&&c()&&(d.listeners=!0),l(this,n,Rt).call(this,{...d,...t})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&l(this,n,et).call(this)}},y=new WeakMap,a=new WeakMap,z=new WeakMap,v=new WeakMap,U=new WeakMap,L=new WeakMap,x=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(Ot)),i},Y=function(){l(this,n,st).call(this);const t=W(this.options.staleTime,s(this,a));if(X||s(this,v).isStale||!dt(t))return;const r=St(s(this,v).dataUpdatedAt,t)+1;o(this,D,setTimeout(()=>{s(this,v).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||!dt(s(this,T))||s(this,T)===0)&&o(this,P,setInterval(()=>{(this.options.refetchIntervalInBackground||Et.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,y).getQueryCache().build(s(this,y),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))},Rt=function(t){yt.batch(()=>{t.listeners&&this.listeners.forEach(i=>{i(s(this,v))}),s(this,y).getQueryCache().notify({query:s(this,a),type:"observerResultsUpdated"})})},gt);function xt(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 xt(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 Tt(e,t){return!J(e.getCurrentResult(),t)}var mt=I.createContext(!1),Ft=()=>I.useContext(mt);mt.Provider;function Ut(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var Dt=I.createContext(Ut()),Pt=()=>I.useContext(Dt);function Mt(e,t){return typeof e=="function"?e(...t):!!e}function _t(){}var Lt=(e,t)=>{(e.suspense||e.throwOnError)&&(t.isReset()||(e.retryOnMount=!1))},jt=e=>{I.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,g,A;const r=It(),d=Ft(),c=Pt(),h=r.defaultQueryOptions(e);(u=(m=r.getDefaultOptions().queries)==null?void 0:m._experimental_beforeQuery)==null||u.call(m,h),h._optimisticResults=d?"isRestoring":"optimistic",Bt(h),Lt(h,c),jt(c);const E=!r.getQueryCache().get(h.queryHash),[p]=I.useState(()=>new t(r,h)),R=p.getOptimisticResult(h);if(I.useSyncExternalStore(I.useCallback(w=>{const Q=d?()=>{}:p.subscribe(yt.batchCalls(w));return p.updateResult(),Q},[p,d]),()=>p.getCurrentResult(),()=>p.getCurrentResult()),I.useEffect(()=>{p.setOptions(h,{listeners:!1})},[h,p]),Ht(h,R))throw vt(h,p,c);if(kt({result:R,errorResetBoundary:c,throwOnError:h.throwOnError,query:r.getQueryCache().get(h.queryHash)}))throw R.error;if((g=(F=r.getDefaultOptions().queries)==null?void 0:F._experimental_afterQuery)==null||g.call(F,h,R),h.experimental_prefetchInRender&&!X&&At(R,d)){const w=E?vt(h,p,c):(A=r.getQueryCache().get(h.queryHash))==null?void 0:A.promise;w==null||w.catch(_t).finally(()=>{p.updateResult()})}return h.notifyOnChangeProps?R:p.trackResult(R)}function Kt(e,t){return zt(e,wt)}export{_t as n,Mt as s,Kt as u};