var nt=i=>{throw TypeError(i)};var K=(i,t,e)=>t.has(i)||nt("Cannot "+e);var s=(i,t,e)=>(K(i,t,"read from private field"),e?e.call(i):t.get(i)),b=(i,t,e)=>t.has(i)?nt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,e),l=(i,t,e,r)=>(K(i,t,"write to private field"),r?r.call(i,e):t.set(i,e),e),f=(i,t,e)=>(K(i,t,"access private method"),e);import{a2 as yt,J as Rt,a3 as gt,a4 as mt,a5 as O,a6 as N,a7 as k,a8 as Ot,a9 as rt,aa as ot,ab as Ct,ac as W,ad as St,ae as wt,af as ht,ag as Qt,ah as It,A as Et,z as _,ai as Ft,aj as Dt,h as Ut,ak as Pt,al as ut,am as lt,an as Mt,ao as Tt}from"./index-C3fBKzZh.js";function xt(i=""){if(!yt())throw new Error("vue-query hooks can only be used inside setup() function or functions that support injection context.");const t=gt(i),e=Rt(t);if(!e)throw new Error("No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.");return e}var y,n,z,R,E,M,w,B,T,x,F,D,I,L,h,A,J,G,X,Y,Z,$,q,pt,ft,Lt=(ft=class extends mt{constructor(t,e){super();b(this,h);b(this,y);b(this,n);b(this,z);b(this,R);b(this,E);b(this,M);b(this,w);b(this,B);b(this,T);b(this,x);b(this,F);b(this,D);b(this,I);b(this,L,new Set);this.options=e,l(this,y,t),l(this,w,null),this.bindMethods(),this.setOptions(e)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(s(this,n).addObserver(this),ct(s(this,n),this.options)?f(this,h,A).call(this):this.updateResult(),f(this,h,Y).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return tt(s(this,n),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return tt(s(this,n),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,f(this,h,Z).call(this),f(this,h,$).call(this),s(this,n).removeObserver(this)}setOptions(t){const e=this.options,r=s(this,n);if(this.options=s(this,y).defaultQueryOptions(t),this.options.enabled!==void 0&&typeof this.options.enabled!="boolean"&&typeof this.options.enabled!="function"&&typeof O(this.options.enabled,s(this,n))!="boolean")throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");f(this,h,q).call(this),s(this,n).setOptions(this.options),e._defaulted&&!N(this.options,e)&&s(this,y).getQueryCache().notify({type:"observerOptionsUpdated",query:s(this,n),observer:this});const o=this.hasListeners();o&&dt(s(this,n),r,this.options,e)&&f(this,h,A).call(this),this.updateResult(),o&&(s(this,n)!==r||O(this.options.enabled,s(this,n))!==O(e.enabled,s(this,n))||k(this.options.staleTime,s(this,n))!==k(e.staleTime,s(this,n)))&&f(this,h,J).call(this);const a=f(this,h,G).call(this);o&&(s(this,n)!==r||O(this.options.enabled,s(this,n))!==O(e.enabled,s(this,n))||a!==s(this,I))&&f(this,h,X).call(this,a)}getOptimisticResult(t){const e=s(this,y).getQueryCache().build(s(this,y),t),r=this.createResult(e,t);return At(this,r)&&(l(this,R,r),l(this,M,this.options),l(this,E,s(this,n).state)),r}getCurrentResult(){return s(this,R)}trackResult(t,e){return new Proxy(t,{get:(r,o)=>(this.trackProp(o),e==null||e(o),Reflect.get(r,o))})}trackProp(t){s(this,L).add(t)}getCurrentQuery(){return s(this,n)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const e=s(this,y).defaultQueryOptions(t),r=s(this,y).getQueryCache().build(s(this,y),e);let o=()=>{},a;const c=new Promise(v=>{a=v,o=s(this,y).getQueryCache().subscribe(m=>{m.type==="updated"&&m.query.queryHash===r.queryHash&&r.state.data!==void 0&&(o(),v(this.createResult(r,e)))})});return Promise.race([r.fetch().then(()=>{const v=this.createResult(r,e);return a==null||a(v),v}).finally(()=>{o()}),c])}fetch(t){return f(this,h,A).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),s(this,R)))}createResult(t,e){var at;const r=s(this,n),o=this.options,a=s(this,R),c=s(this,E),v=s(this,M),m=t!==r?t.state:s(this,z),{state:V}=t;let p={...V},j=!1,d;if(e._optimisticResults){const S=this.hasListeners(),bt=!S&&ct(t,e),vt=S&&dt(t,r,e,o);(bt||vt)&&(p={...p,...wt(V.data,t.options)}),e._optimisticResults==="isRestoring"&&(p.fetchStatus="idle")}let{error:u,errorUpdatedAt:C,status:g}=p;d=p.data;let Q=!1;if(e.placeholderData!==void 0&&d===void 0&&g==="pending"){let S;a!=null&&a.isPlaceholderData&&e.placeholderData===(v==null?void 0:v.placeholderData)?(S=a.data,Q=!0):S=typeof e.placeholderData=="function"?e.placeholderData((at=s(this,x))==null?void 0:at.state.data,s(this,x)):e.placeholderData,S!==void 0&&(g="success",d=ht(a==null?void 0:a.data,S,e),j=!0)}if(e.select&&d!==void 0&&!Q)if(a&&d===(c==null?void 0:c.data)&&e.select===s(this,B))d=s(this,T);else try{l(this,B,e.select),d=e.select(d),d=ht(a==null?void 0:a.data,d,e),l(this,T,d),l(this,w,null)}catch(S){l(this,w,S)}else d===void 0&&l(this,w,null);s(this,w)&&(u=s(this,w),d=s(this,T),C=Date.now(),g="error",j=!1);const U=p.fetchStatus==="fetching",P=g==="pending",H=g==="error",st=P&&U,it=d!==void 0;return{status:g,fetchStatus:p.fetchStatus,isPending:P,isSuccess:g==="success",isError:H,isInitialLoading:st,isLoading:st,data:d,dataUpdatedAt:p.dataUpdatedAt,error:u,errorUpdatedAt:C,failureCount:p.fetchFailureCount,failureReason:p.fetchFailureReason,errorUpdateCount:p.errorUpdateCount,isFetched:t.isFetched(),isFetchedAfterMount:p.dataUpdateCount>m.dataUpdateCount||p.errorUpdateCount>m.errorUpdateCount,isFetching:U,isRefetching:U&&!P,isLoadingError:H&&!it,isPaused:p.fetchStatus==="paused",isPlaceholderData:j,isRefetchError:H&&it,isStale:et(t,e),refetch:this.refetch,isEnabled:O(e.enabled,t)!==!1}}updateResult(){const t=s(this,R),e=this.createResult(s(this,n),this.options);if(l(this,E,s(this,n).state),l(this,M,this.options),s(this,E).data!==void 0&&l(this,x,s(this,n)),N(e,t))return;l(this,R,e);const r=()=>{if(!t)return!0;const{notifyOnChangeProps:o}=this.options,a=typeof o=="function"?o():o;if(a==="all"||!a&&!s(this,L).size)return!0;const c=new Set(a??s(this,L));return this.options.throwOnError&&c.add("error"),Object.keys(s(this,R)).some(v=>{const m=v;return s(this,R)[m]!==t[m]&&c.has(m)})};f(this,h,pt).call(this,{listeners:r()})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&f(this,h,Y).call(this)}},y=new WeakMap,n=new WeakMap,z=new WeakMap,R=new WeakMap,E=new WeakMap,M=new WeakMap,w=new WeakMap,B=new WeakMap,T=new WeakMap,x=new WeakMap,F=new WeakMap,D=new WeakMap,I=new WeakMap,L=new WeakMap,h=new WeakSet,A=function(t){f(this,h,q).call(this);let e=s(this,n).fetch(this.options,t);return t!=null&&t.throwOnError||(e=e.catch(Ot)),e},J=function(){f(this,h,Z).call(this);const t=k(this.options.staleTime,s(this,n));if(rt.isServer()||s(this,R).isStale||!ot(t))return;const e=Ct(s(this,R).dataUpdatedAt,t)+1;l(this,F,W.setTimeout(()=>{s(this,R).isStale||this.updateResult()},e))},G=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(s(this,n)):this.options.refetchInterval)??!1},X=function(t){f(this,h,$).call(this),l(this,I,t),!(rt.isServer()||O(this.options.enabled,s(this,n))===!1||!ot(s(this,I))||s(this,I)===0)&&l(this,D,W.setInterval(()=>{(this.options.refetchIntervalInBackground||St.isFocused())&&f(this,h,A).call(this)},s(this,I)))},Y=function(){f(this,h,J).call(this),f(this,h,X).call(this,f(this,h,G).call(this))},Z=function(){s(this,F)!==void 0&&(W.clearTimeout(s(this,F)),l(this,F,void 0))},$=function(){s(this,D)!==void 0&&(W.clearInterval(s(this,D)),l(this,D,void 0))},q=function(){const t=s(this,y).getQueryCache().build(s(this,y),this.options);if(t===s(this,n))return;const e=s(this,n);l(this,n,t),l(this,z,t.state),this.hasListeners()&&(e==null||e.removeObserver(this),t.addObserver(this))},pt=function(t){Qt.batch(()=>{t.listeners&&this.listeners.forEach(e=>{e(s(this,R))}),s(this,y).getQueryCache().notify({query:s(this,n),type:"observerResultsUpdated"})})},ft);function jt(i,t){return O(t.enabled,i)!==!1&&i.state.data===void 0&&!(i.state.status==="error"&&O(t.retryOnMount,i)===!1)}function ct(i,t){return jt(i,t)||i.state.data!==void 0&&tt(i,t,t.refetchOnMount)}function tt(i,t,e){if(O(t.enabled,i)!==!1&&k(t.staleTime,i)!=="static"){const r=typeof e=="function"?e(i):e;return r==="always"||r!==!1&&et(i,t)}return!1}function dt(i,t,e,r){return(i!==t||O(r.enabled,i)===!1)&&(!e.suspense||i.state.status!=="error")&&et(i,e)}function et(i,t){return O(t.enabled,i)!==!1&&i.isStaleByTime(k(t.staleTime,i))}function At(i,t){return!N(i.getCurrentResult(),t)}function kt(i,t,e){const r=xt(),o=Ut(()=>{var Q;let u=t;typeof u=="function"&&(u=u());const C=Mt(u);typeof C.enabled=="function"&&(C.enabled=C.enabled());const g=r.defaultQueryOptions(C);return g._optimisticResults=(Q=r.isRestoring)!=null&&Q.value?"isRestoring":"optimistic",g}),a=new i(r,o.value),c=o.value.shallow?It(a.getCurrentResult()):Et(a.getCurrentResult());let v=()=>{};r.isRestoring&&_(r.isRestoring,u=>{u||(v(),v=a.subscribe(C=>{lt(c,C)}))},{immediate:!0});const m=()=>{a.setOptions(o.value),lt(c,a.getCurrentResult())};_(o,m),Tt(()=>{v()});const V=(...u)=>(m(),c.refetch(...u)),p=()=>new Promise((u,C)=>{let g=()=>{};const Q=()=>{if(o.value.enabled!==!1){a.setOptions(o.value);const U=a.getOptimisticResult(o.value);U.isStale?(g(),a.fetchOptimistic(o.value).then(u,P=>{ut(o.value.throwOnError,[P,a.getCurrentQuery()])?C(P):u(a.getCurrentResult())})):(g(),u(U))}};Q(),g=_(o,Q)});_(()=>c.error,u=>{if(c.isError&&!c.isFetching&&ut(o.value.throwOnError,[u,a.getCurrentQuery()]))throw u});const j=o.value.shallow?Ft(c):Dt(c),d=Pt(j);for(const u in c)typeof c[u]=="function"&&(d[u]=c[u]);return d.suspense=p,d.refetch=V,d}function Vt(i,t){return kt(Lt,i)}export{Vt as u};