import{a as e,i as t,n,t as r}from"./useQuery-CiIFqdui.js";import{t as i}from"./useMutation-CT-1Sa-S.js";import{t as a}from"./client-Cjdmbj0a.js";import{B as o,R as s,z as c}from"./index-BV_X4mzm.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: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:l}=r,u=n.fetchMeta?.fetchMore?.direction,d=o&&u===`forward`,f=i&&u===`forward`,p=o&&u===`backward`,m=i&&u===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:s(t,n.data),hasPreviousPage:c(t,n.data),isFetchNextPageError:d,isFetchingNextPage:f,isFetchPreviousPageError:p,isFetchingPreviousPage:m,isRefetchError:l&&!d&&!p,isRefetching:a&&!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`),a.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:()=>a.get(`/api/v1/items/${e}`),enabled:!!e})}function p(){let e=t();return i({mutationFn:e=>a.post(`/api/v1/items`,e),onSuccess:()=>e.invalidateQueries({queryKey:[`items`]})})}function m(){let e=t();return i({mutationFn:({id:e,...t})=>a.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 i({mutationFn:e=>a.del(`/api/v1/items/${e}`),onSuccess:()=>e.invalidateQueries({queryKey:[`items`]})})}function g(e){return r({queryKey:[`search`,e],queryFn:()=>a.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};