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