"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),T=require("lodash-unified");require("../../config-provider/index.js");const b=require("../utils.js"),Y=require("./use-sorted-filtered.js"),Z=require("../../config-provider/hooks/use-locale.js"),I=require("../../config-provider/hooks/use-namespace.js"),ee=({manual:O=!1,defaultCurrent:j=1,defaultPageSize:F=10,request:D,defaultParams:E={},defaultData:R=[],formatParams:P,paramsValueTypeMap:q,resetFieldsIgnores:x,filterFields:M,sortFields:B,showLessItems:v=!1,showTotal:K=!0,pagination:f=!0})=>{let S=0,s={};const L=t=>P?P(t):t,c=e.ref(),i=e.ref(f?j:void 0),d=e.ref(f?F:void 0),{getColumnSFConfig:_,setSF:$,clearAll:k}=Y.useTableSortedAndFiltered(),{t:p}=Z.useLocale(),{b:m}=I.useNamespace("ap-table"),n=e.ref({total:0,records:R,loading:!1}),z=async t=>{const a=L(t),r=Date.now();S=r,n.value.loading=!0;try{const o=await D({...E,...a});S===r&&(n.value.total=o.total||o.data?.length||0,n.value.records=[...o.data||[]])}catch{S===r&&(n.value.records=[],n.value.total=0)}finally{n.value.loading=!1}},V=t=>{const a={};return Object.entries(t).forEach(([r,o])=>{if(a[r]=o,q&&o){const l=q[r];l&&(a[r]=b.parseFieldValue(l,o))}}),a},J=async t=>{const a=c.value?.apForm?.getFieldsValueTransformed(!0)||{},r={};Object.entries(a).forEach(([o,l])=>{x&&x.indexOf(o)>-1&&(r[o]=l)}),await c.value?.apForm?.resetFields(),c.value?.apForm?.setFieldsValue?.(r),e.nextTick(()=>{t?.()})},h=t=>{s=t;const a=V(t);z(a)},Q=t=>{h({...s,...t})},y=()=>{const t=c.value?.apForm?.getFieldsValueTransformed(!0)||{};f&&(i.value=1),h({...t,filter:s.filter,sort:s.sort,current:f?1:void 0,pageSize:f?s.pageSize||F:void 0})},U=()=>{k(),s.sort={},s.filter={},J(y)},C=()=>{h(s)},W=t=>{if(!f)C();else{const a=e.unref(i),r=e.unref(d),o=e.unref(n).total-t,l=Math.ceil(o/r),g=a>l?l:a;Q({current:g>0?g:1})}},N=(t,a,r)=>{const o=c.value?.apForm?.getFieldsValueTransformed(!0)||{};i.value=t.current,d.value=t.pageSize,$(a,r);const l=T.isArray(r)?[...r]:[r],g={};for(const u of l)e.unref(B)?.includes(u.columnKey||u.field)&&u.order&&(g[b.dataIndexToStr(u.columnKey||u.field)]=u.order);const w={};for(const u of Object.keys(a))e.unref(M)?.includes(u)&&a[u]&&(w[u]=a[u]);const A={...o,filter:w,sort:g,current:t.current,pageSize:t.pageSize};T.isEqualWith(s,A,b.isEqualCustom)||h(A)};e.onMounted(()=>{const t=c.value?.apForm?.getFieldsValueTransformed(!0)||{};if(s={current:e.unref(i),pageSize:e.unref(d),filter:{},sort:{},...t},!O){const a=V(s);z(a)}});const G=e.computed(()=>e.unref(n).total===0?"-":`${e.unref(i.value)}/${Math.ceil(e.unref(n).total/e.unref(d))}`);function H(t){T.isArray(t)&&(n.value.records=t,n.value.total=t.length)}const X=e.computed(()=>({loading:e.unref(n).loading,pagination:{current:e.unref(i),pageSize:e.unref(d),total:e.unref(n).total,showSizeChanger:!v,showQuickJumper:!v,showLessItems:v,size:"default",showTotal:K?t=>e.createVNode("span",{class:m("pagination-total-wrapper")},[p("ap.apTable.pagination.totalLeftPrefix")," ",e.createVNode("span",{class:m("pagination-count-text")},[t])," ",p("ap.apTable.pagination.totalLeftSuffix"),e.createVNode("span",{class:m("pagination--total-right")},[p("ap.apTable.pagination.totalRightPrefix")," ",e.createVNode("span",{class:m("pagination-count-text")},[e.unref(G)])," ",p("ap.apTable.pagination.totalRightSuffix")])]):void 0},onChange:N,dataSource:e.unref(n).records}));return{formRef:c,submit:y,reset:U,refresh:C,refreshByDelete:W,data:n,current:i,pageSize:d,handleTableChange:N,tableProps:X,dataSource:e.computed(()=>e.unref(n).records),setDataSource:H,getColumnSFConfig:_}};exports.useTablePaging=ee;
