import{r as t,a as x}from"./main-BzPVmAp-.js";const v=({url:r,pageApi:l,params:n,map:c,initialPageSize:S=10})=>{const[p,d]=t.useState([]),[a,g]=t.useState(1),[y,m]=t.useState(0),[w,u]=t.useState(!1),[s,P]=t.useState(S),[i,b]=t.useState(""),h=o=>{b(o),g(1)},f=async o=>{u(!0);try{let e;r?e=await x.post(r,{...n,page_number:o,page_size:s,keywords:i||void 0}):e=await l({...n,page_number:o,page_size:s,keywords:i||void 0});const{items:_,total:k,...E}=e.data;c?(e.data=_.map(c),d(e.data)):d(e.data.items),m(k)}catch(e){console.error("Error fetching data:",e)}finally{u(!1)}},z=()=>{f(a)};return t.useEffect(()=>{f(a)},[a,i,s,r,JSON.stringify(n)]),{data:p,pageNumber:a,totalPage:y,loading:w,setPageNumber:g,setPageSize:P,pageSize:s,reload:z,search:h}};export{v as u};
