import{d as y}from"./index-CJx7RGCD.js";import{cb as R,cc as z,a3 as F,k as d,a9 as U,aw as b}from"./app-CgV11GBz.js";function m(e,f){return e&&R(e,z(f))}const T=()=>{const e=F({data:[],pagination:{pageSize:10,showSizeChanger:!0},loading:!1,sorter:{},searchColumn:void 0,searchString:"",searchStatus:void 0,filterLoading:!1,filterableColumns:[],selectedRowKeys:[],tableColumns:[]}),f=d(1),i=d({}),g=d([]),$=d(""),v=d({allowExport:!1,exportType:""}),S=a=>{const s=a.limit,r=(a.page-1)*s,t=C(s,r);return $.value=t,axiosAdmin.get(t)},C=(a,s)=>{var r=i.value.url,t="",l="",o=!1,p=!1;if("filterString"in i.value&&i.value.filterString!=""&&typeof i.value.filterString=="string"&&(t+=`${i.value.filterString} and `,o=!0),typeof i.value.filters=="object"&&m(i.value.filters,(n,c)=>{n!=null&&n!=""&&(t+=`${c} eq "${n}" and `,o=!0,b(g.value,c)&&(l+=`${n},`,p=!0))}),e.searchColumn!=null&&e.searchString!="")t+=`${e.searchColumn} lk "%${e.searchString}%" and `,o=!0,e.filterLoading=!0;else if(e.searchString!=""&&e.filterableColumns.length>0){var u="";U(e.filterableColumns,n=>{u+=`${n.key} lk "%${e.searchString}%" or `}),u.length>0&&(t+=`(${u.substring(0,u.length-3)})`,o=!1),e.filterLoading=!0}if(t.length>0&&o==!0?r+=`&filters=${encodeURIComponent(t.substring(0,t.length-5))}`:t.length>0&&o==!1&&(r+=`&filters=${encodeURIComponent(t)}`),i.value.extraFilters&&typeof i.value.extraFilters=="object"&&m(i.value.extraFilters,(n,c)=>{n!=null&&n!=""&&(r+=`&${c}=${n}`,b(g.value,c)&&(l+=`${n},`,p=!0))}),e.sorter&&e.sorter.field){const n=e.sorter.order=="ascend"||e.sorter.order=="asc"?"asc":"desc";r+=`&order=${e.sorter.field} ${n}`}else r+="&order=id desc";return r+=`&offset=${s}&limit=${a}`,p&&(l=l.substring(0,l.length-1),r+=`&hashable=${l}`),r},x=(a,s,r)=>{const t={...e.pagination};t.current=a.current,t.pageSize=a.pageSize,e.pagination=t,f.value=a.current,r=e.sorter,h({limit:a.pageSize,page:a.current,sortField:r.field,sortOrder:r.order,...s})},h=(a={})=>{e.loading=!0,S({limit:e.pagination.pageSize,page:f.value,...a}).then(s=>{const r=s.data,t={...e.pagination};t.total=s.meta.paging.total,e.loading=!1,e.data=r,e.pagination=t,e.filterLoading=!1,e.selectedRowKeys=[],a.success!=null&&a.success(r)})},w=y(()=>{h({page:1})},400);return{table:e,tableUrl:i,exportDetails:v,currentPage:f,hashable:g,handleTableChange:x,fetch:h,onTableSearch:w,onRowSelectChange:a=>{e.selectedRowKeys=a}}};export{T as d};
