import{a as e,i as t,n,t as r}from"./useQuery-qKYvnzn0.js";import{n as i,r as a,t as o}from"./infiniteQueryBehavior-CnCcMwPB.js";import{t as s}from"./useMutation-C6r_dxL-.js";import{t as c}from"./client-BAPwymp0.js";var l=class extends e{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:a()})}getOptimisticResult(e){return e.behavior=a(),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:a,isRefetching:s,isError:c,isRefetchError:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=c&&u===`forward`,f=a&&u===`forward`,p=c&&u===`backward`,m=a&&u===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:o(t,n.data),hasPreviousPage:i(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:l&&!d&&!p,isRefetching:s&&!f&&!m}}};function u(e,t){return n(e,l,t)}function d(e={}){let t=new URLSearchParams;return Object.entries(e).forEach(([e,n])=>{n!=null&&t.set(e,String(n))}),u({queryKey:[`items`,e],queryFn:async({pageParam:e=0})=>(t.set(`offset`,String(e)),t.set(`limit`,`20`),c.get(`/api/v1/items?${t.toString()}`)),getNextPageParam:(e,t)=>e.length===20?t.length*20:void 0,initialPageParam:0})}function f(e){return r({queryKey:[`item`,e],queryFn:()=>c.get(`/api/v1/items/${e}`),enabled:!!e})}function p(){let e=t();return s({mutationFn:e=>c.post(`/api/v1/items`,e),onSuccess:()=>e.invalidateQueries({queryKey:[`items`]})})}function m(){let e=t();return s({mutationFn:({id:e,...t})=>c.patch(`/api/v1/items/${e}`,t),onSuccess:(t,n)=>{e.invalidateQueries({queryKey:[`items`]}),e.invalidateQueries({queryKey:[`item`,n.id]})}})}function h(){let e=t();return s({mutationFn:e=>c.del(`/api/v1/items/${e}`),onSuccess:()=>e.invalidateQueries({queryKey:[`items`]})})}function g(e){return r({queryKey:[`search`,e],queryFn:()=>c.get(`/api/v1/search?q=${encodeURIComponent(e)}`),enabled:e.length>=2})}export{g as a,d as i,h as n,m as o,f as r,p as t};