import{r as n}from"./index-BP8_t0zE.js";import{S as d,a as p}from"./useGetList-Dit6Yzrj.js";var g=function(e,r){switch(r.type){case"SET_SORT":return r.payload;case"SET_SORT_FIELD":{var t=r.payload,a=e.field===t?e.order===d?p:d:d;return{field:t,order:a}}case"SET_SORT_ORDER":{var a=r.payload;if(!e.field)throw new Error("cannot change the order on an undefined sort field");return{field:e.field,order:a}}default:return e}},l={field:"",order:"ASC"},_=function(e){e===void 0&&(e=l);var r=n.useReducer(g,e),t=r[0],a=r[1],u=n.useRef(!0);return n.useEffect(function(){if(u.current){u.current=!1;return}a({type:"SET_SORT",payload:e})},[e.field,e.order]),{setSort:n.useCallback(function(o){return a({type:"SET_SORT",payload:o})},[a]),setSortField:n.useCallback(function(o){return a({type:"SET_SORT_FIELD",payload:o})},[a]),setSortOrder:n.useCallback(function(o){return a({type:"SET_SORT_ORDER",payload:o})},[a]),sort:t}},s=function(){return s=Object.assign||function(e){for(var r,t=1,a=arguments.length;t<a;t++){r=arguments[t];for(var u in r)Object.prototype.hasOwnProperty.call(r,u)&&(e[u]=r[u])}return e},s.apply(this,arguments)},S=function(e,r){return s(s({},e),r)},R={page:1,perPage:25};const E=function(e){e===void 0&&(e={});var r=n.useReducer(S,s(s({},R),e)),t=r[0],a=r[1],u=n.useRef(!0),o=n.useCallback(function(f){return a({perPage:f,page:1})},[]),c=n.useCallback(function(f){return a({page:f})},[]);return n.useEffect(function(){if(u.current){u.current=!1;return}o(e.perPage||25)},[e.perPage,o]),{page:t.page,perPage:t.perPage,pagination:t,setPage:c,setPerPage:o,setPagination:a}};export{_ as a,E as u};
