"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),O=require("@aplus-frontend/antdv"),i=require("lodash-unified"),j=require("../utils/warning.js"),p=require("../ap-form/index.js");require("../config-provider/index.js");require("../hooks/index.js");require("../utils/index.js");const z=require("./hooks/use-get-columns.js"),K=require("./style/index.js"),$=require("./utils.js"),G=require("../config-provider/hooks/use-namespace.js"),U=require("../hooks/useControllableValue.js"),H=require("../config-provider/hooks/use-global-config.js"),g=require("../utils/is.js"),W=n.defineComponent({name:"EditableTable",__name:"index",props:{dropdownPrefixCls:{},pagination:{type:[Boolean,Object],default:!1},loading:{type:[Boolean,Object],default:void 0},size:{default:"small"},bordered:{type:Boolean,default:!1},locale:{},onResizeColumn:{},rowSelection:{},getPopupContainer:{},scroll:{},sortDirections:{default:()=>["ascend","descend"]},showSorterTooltip:{type:[Boolean,Object],default:!0},prefixCls:{},rowKey:{type:[String,Function],default:"key"},tableLayout:{default:"fixed"},rowClassName:{},title:{},footer:{},id:{},showHeader:{type:Boolean,default:!0},components:{},customRow:{},customHeaderRow:{},direction:{},expandFixed:{type:[String,Boolean],default:!1},expandColumnWidth:{},expandedRowKeys:{},defaultExpandedRowKeys:{},expandedRowRender:{},expandRowByClick:{type:Boolean,default:!1},expandIcon:{},onExpand:{},onExpandedRowsChange:{},defaultExpandAllRows:{type:Boolean,default:!1},indentSize:{default:15},expandIconColumnIndex:{},showExpandColumn:{type:Boolean,default:!0},expandedRowClassName:{},childrenColumnName:{default:"children"},rowExpandable:{},sticky:{type:[Boolean,Object]},transformCellText:{},rowHoverable:{type:Boolean},columns:{},value:{},defaultValue:{},"onUpdate:value":{},onChange:{},maxLength:{},name:{default:"ap-editable-table-inner-name"},onFieldChange:{}},emits:["update:value"],setup(m,{expose:b,emit:w}){const t=m;j.useDevWarning("EditableTable")(!1,"breaking","EditableTable has been EOL, Please use EditableAgGrid(https://aplus.aplnk.com/aplus-ui/components/ag-grid/editable/) instead.");const{b:v}=G.useNamespace("editable-table"),x=K.default("editable-table"),y=n.useSlots(),C=w,h=n.shallowRef(),{value:d,updateValue:R}=U.useControllableValue(t,C),r=n.ref(),F=H.useGlobalConfig("valueTypeMap"),c=p.ApForm.useWatch(t.name,r);n.watch(()=>c.value,e=>{R(e),t.onChange?.(e)},{deep:!0,flush:"post"}),n.watch(d,e=>{e!==n.unref(c)&&(i.isEqual(e,n.unref(c))||r.value?.setFieldValue(t.name,e))},{deep:!0});const q=z.default(t,F);function B(){r.value?.resetFields()}function T(e){return e?(i.isArray(e)?e:[e]).map(l=>i.isArray(l)?[t.name,...l]:[t.name,l]):void 0}async function V(e,u){return(await r.value?.validateFields(T(e),u))?.[t.name]}function E(e,u){const l=n.unref(d)?.length||0;if(g.isDef(t.maxLength)&&l>=t.maxLength)return;const a={...e||{}};r.value?.setFieldValue?.(t.name,a,!0,(o,s)=>{if(!o[s]){o[s]=[a];return}i.isUndefined(u)?o[s].push(a):o[s].splice(u,0,a)})}function N(e,u="suffix"){const l=n.unref(d)?.length||0,a=i.isNumber(e)?e:e.length;if(g.isDef(t.maxLength)&&l+a>t.maxLength)return;const o=i.isNumber(e)?new Array(e).fill(0).map(()=>({})):i.cloneDeep(e);r.value?.setFieldValue?.(t.name,o,!0,(s,f)=>{if(!s[f]){s[f]=[...o];return}u==="suffix"?s[f].push(...o):s[f].unshift(...o)})}function S(e){const u=new Set(i.isNumber(e)?[e]:e);r.value?.setFieldValue?.(t.name,void 0,!0,(l,a)=>{l[a]=l[a].filter((o,s)=>!u.has(s))})}function A(e){const u=new Set(i.isArray(e)?e:[e]);u.size!==0&&r.value?.setFieldValue?.(t.name,void 0,!0,(l,a)=>{l[a]=l[a].filter(o=>!u.has(o[t.rowKey]))})}function D(){return n.unref(d)}function L(e){r.value?.setFieldValue(t.name,e)}function _(e){return n.unref(d)?.[e]}function k(e,u,l=!0){r.value?.setFieldValue?.(t.name,void 0,!0,(a,o)=>{!a[o]||!a[o][e]||(a[o][e]={...l?a[o][e]:{},...u})})}function P(e,u){const l=e==="end"?d.value.length-1:e;$.scrollToRowIndex(l,h.value?.$el,u)}function I(){r.value?.setFieldValue?.(t.name,[])}return b({resetFields:B,validateFields:V,add:E,remove:S,getRowData:_,getRowsData:D,setRowData:k,addMultiple:N,scrollTo:P,clear:I,setTableData:L,removeByKey:A}),(e,u)=>(n.openBlock(),n.createBlock(n.unref(p.ApForm),{ref_key:"formRef",ref:r,"initial-values":{[t.name]:n.unref(d)}},{default:n.withCtx(()=>[n.createVNode(n.unref(p.ApForm).FormItem,{name:m.name,"no-style":""},{default:n.withCtx(()=>[n.createVNode(n.unref(O.Table),n.mergeProps(n.unref(i.omit)(t,["name","value","onUpdate:value","maxLength","onChange"]),{ref_key:"tableRef",ref:h,class:[n.unref(v)(),n.unref(x)],columns:n.unref(q),"data-source":n.unref(d)}),n.createSlots({_:2},[n.renderList(n.unref(i.omit)(y,["headerCell"]),(l,a)=>({name:a,fn:n.withCtx(o=>[n.renderSlot(e.$slots,a,n.normalizeProps(n.guardReactiveProps(o||{})))])}))]),1040,["class","columns","data-source"])]),_:3},8,["name"])]),_:3},8,["initial-values"]))}});exports.default=W;
