import{C as e,S as t,b as n,h as r,r as i,x as a}from"./useMutation-YNiikd7W.js";function o(r){return{onFetch:(i,o)=>{let l=i.options,u=i.fetchOptions?.meta?.fetchMore?.direction,d=i.state.data?.pages||[],f=i.state.data?.pageParams||[],p={pages:[],pageParams:[]},m=0,h=async()=>{let o=!1,h=e=>{n(e,()=>i.signal,()=>o=!0)},g=e(i.options,i.fetchOptions),_=async(e,n,r)=>{if(o)return Promise.reject();if(n==null&&e.pages.length)return Promise.resolve(e);let s=await g((()=>{let e={client:i.client,queryKey:i.queryKey,pageParam:n,direction:r?`backward`:`forward`,meta:i.options.meta};return h(e),e})()),{maxPages:c}=i.options,l=r?t:a;return{pages:l(e.pages,s,c),pageParams:l(e.pageParams,n,c)}};if(u&&d.length){let e=u===`backward`,t=e?c:s,n={pages:d,pageParams:f};p=await _(n,t(l,n),e)}else{let e=r??d.length;do{let e=m===0?f[0]??l.initialPageParam:s(l,p);if(m>0&&e==null)break;p=await _(p,e),m++}while(m<e)}return p};i.options.persister?i.fetchFn=()=>i.options.persister?.(h,{client:i.client,queryKey:i.queryKey,meta:i.options.meta,signal:i.signal},o):i.fetchFn=h}}}function s(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 c(e,{pages:t,pageParams:n}){return t.length>0?e.getPreviousPageParam?.(t[0],t,n[0],n):void 0}function l(e,t){return t?s(e,t)!=null:!1}function u(e,t){return!t||!e.getPreviousPageParam?!1:c(e,t)!=null}var d=class extends r{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){super.setOptions({...e,behavior:o()})}getOptimisticResult(e){return e.behavior=o(),super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,d=o&&c===`forward`,f=i&&c===`forward`,p=o&&c===`backward`,m=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:l(t,n.data),hasPreviousPage:u(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:s&&!d&&!p,isRefetching:a&&!f&&!m}}};function f(e,t){return i(e,d,t)}export{o as n,f as t};