import{r as o,j as w,s as m,n as v,a as C,i as Q,Q as I,M as T}from"./vendor-DdPBfMMb.js";var b=o.createContext(void 0),x=e=>{const s=o.useContext(b);if(!s)throw new Error("No QueryClient set, use QueryClientProvider to set one");return s},L=({client:e,children:s})=>(o.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),w.jsx(b.Provider,{value:e,children:s})),p=o.createContext(!1),O=()=>o.useContext(p);p.Provider;function P(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var N=o.createContext(P()),d=()=>o.useContext(N),B=(e,s,a)=>{const r=a!=null&&a.state.error&&typeof e.throwOnError=="function"?m(e.throwOnError,[a.state.error,a]):e.throwOnError;(e.suspense||e.experimental_prefetchInRender||r)&&(s.isReset()||(e.retryOnMount=!1))},k=e=>{o.useEffect(()=>{e.clearReset()},[e])},U=({result:e,errorResetBoundary:s,throwOnError:a,query:r,suspense:n})=>e.isError&&!s.isReset()&&!e.isFetching&&r&&(n&&e.data===void 0||m(a,[e.error,r])),j=e=>{if(e.suspense){const a=n=>n==="static"?n:Math.max(n??1e3,1e3),r=e.staleTime;e.staleTime=typeof r=="function"?(...n)=>a(r(...n)):a(r),typeof e.gcTime=="number"&&(e.gcTime=Math.max(e.gcTime,1e3))}},F=(e,s)=>e.isLoading&&e.isFetching&&!s,H=(e,s)=>(e==null?void 0:e.suspense)&&s.isPending,g=(e,s,a)=>s.fetchOptimistic(e).catch(()=>{a.clearReset()});function D(e,s,a){var E,R,h,S;const r=O(),n=d(),i=x(),t=i.defaultQueryOptions(e);(R=(E=i.getDefaultOptions().queries)==null?void 0:E._experimental_beforeQuery)==null||R.call(E,t);const c=i.getQueryCache().get(t.queryHash);t._optimisticResults=r?"isRestoring":"optimistic",j(t),B(t,n,c),k(n);const M=!i.getQueryCache().get(t.queryHash),[u]=o.useState(()=>new s(i,t)),l=u.getOptimisticResult(t),y=!r&&e.subscribed!==!1;if(o.useSyncExternalStore(o.useCallback(f=>{const _=y?u.subscribe(v.batchCalls(f)):C;return u.updateResult(),_},[u,y]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),o.useEffect(()=>{u.setOptions(t)},[t,u]),H(t,l))throw g(t,u,n);if(U({result:l,errorResetBoundary:n,throwOnError:t.throwOnError,query:c,suspense:t.suspense}))throw l.error;if((S=(h=i.getDefaultOptions().queries)==null?void 0:h._experimental_afterQuery)==null||S.call(h,t,l),t.experimental_prefetchInRender&&!Q&&F(l,r)){const f=M?g(t,u,n):c==null?void 0:c.promise;f==null||f.catch(C).finally(()=>{u.updateResult()})}return t.notifyOnChangeProps?l:u.trackResult(l)}function V(e,s){return D(e,I)}function q(e,s){const a=x(),[r]=o.useState(()=>new T(a,e));o.useEffect(()=>{r.setOptions(e)},[r,e]);const n=o.useSyncExternalStore(o.useCallback(t=>r.subscribe(v.batchCalls(t)),[r]),()=>r.getCurrentResult(),()=>r.getCurrentResult()),i=o.useCallback((t,c)=>{r.mutate(t,c).catch(C)},[r]);if(n.error&&m(r.options.throwOnError,[n.error]))throw n.error;return{...n,mutate:i,mutateAsync:n.mutate}}export{L as Q,V as a,q as b,x as u};
