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