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