import{d as e,f as t,m as n,p as r}from"./useQuery-qKYvnzn0.js";function i(i){return{onFetch:(s,c)=>{let l=s.options,u=s.fetchOptions?.meta?.fetchMore?.direction,d=s.state.data?.pages||[],f=s.state.data?.pageParams||[],p={pages:[],pageParams:[]},m=0,h=async()=>{let c=!1,h=t=>{e(t,()=>s.signal,()=>c=!0)},g=n(s.options,s.fetchOptions),_=async(e,n,i)=>{if(c)return Promise.reject();if(n==null&&e.pages.length)return Promise.resolve(e);let a=await g((()=>{let e={client:s.client,queryKey:s.queryKey,pageParam:n,direction:i?`backward`:`forward`,meta:s.options.meta};return h(e),e})()),{maxPages:o}=s.options,l=i?r:t;return{pages:l(e.pages,a,o),pageParams:l(e.pageParams,n,o)}};if(u&&d.length){let e=u===`backward`,t=e?o:a,n={pages:d,pageParams:f};p=await _(n,t(l,n),e)}else{let e=i??d.length;do{let e=m===0?f[0]??l.initialPageParam:a(l,p);if(m>0&&e==null)break;p=await _(p,e),m++}while(m<e)}return p};s.options.persister?s.fetchFn=()=>s.options.persister?.(h,{client:s.client,queryKey:s.queryKey,meta:s.options.meta,signal:s.signal},c):s.fetchFn=h}}}function a(e,{pages:t,pageParams:n}){let r=t.length-1;return t.length>0?e.getNextPageParam(t[r],t,n[r],n):void 0}function o(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}function s(e,t){return t?a(e,t)!=null:!1}function c(e,t){return!t||!e.getPreviousPageParam?!1:o(e,t)!=null}export{c as n,i as r,s as t};