import{a as t}from"./vendor-query-B2UbickB.js";import{f as F}from"./vendor-react-CXumBFUA.js";function N(z){var h,C;const m=t.useRef(z),f=((h=m.current)==null?void 0:h.filters)??{},p=t.useMemo(()=>Object.keys(f),[]),i=((C=m.current)==null?void 0:C.pageSize)??25,[a,b]=F(),d=t.useRef(b);t.useEffect(()=>{d.current=b});const R=t.useMemo(()=>{const e={};for(const s of p)e[s]=a.get(s)??f[s];return e},[a,p,f]),l=Number(a.get("page"))||1,o=Number(a.get("pageSize"))||i,S=t.useMemo(()=>(l-1)*o,[l,o]),r=t.useCallback((e,s=!1)=>{d.current(g=>{const n=new URLSearchParams(g);for(const[M,u]of Object.entries(e))u===null||u===""||u===void 0?n.delete(M):n.set(M,u);return n},{replace:s})},[]),_=t.useCallback((e,s)=>{r({[e]:s||null,page:null})},[r]),x=t.useCallback(e=>{const s={page:null};for(const[g,n]of Object.entries(e))s[g]=n||null;r(s)},[r]),k=t.useCallback(e=>{r({page:e<=1?null:String(e)},!0)},[r]),P=t.useCallback(e=>{r({pageSize:e===i?null:String(e),page:null},!0)},[r,i]),y=t.useCallback(e=>Math.max(1,Math.ceil(e/o)),[o]),j=t.useMemo(()=>({page:l,pageSize:o,offset:S,setPage:k,setPageSize:P,totalPages:y}),[l,o,S,k,P,y]),c=t.useMemo(()=>({sort_by:a.get("sort_by")??"",order:a.get("order")||"desc"}),[a]),v=t.useCallback(e=>{const s=c.sort_by===e;r({sort_by:e||null,order:s&&c.order==="desc"?"asc":"desc",page:null})},[c.sort_by,c.order,r]);return{filters:R,setFilter:_,setFilters:x,pagination:j,sort:c,setSort:v}}export{N as u};
//# sourceMappingURL=useFilterParams-x-Dg0Vgz.js.map
