"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),k=require("@aplus-frontend/antdv"),u=require("lodash-unified"),P=require("../ap-form/utils/get.js"),j=require("../utils/warning.js"),p=require("../ap-form/index.js"),A=require("../ap-form/context.js");require("../config-provider/index.js");require("../utils/index.js");const O=require("./hooks/use-get-columns.js"),_=require("./style/index.js"),z=require("./utils.js"),K=require("../config-provider/hooks/use-namespace.js"),$=require("../config-provider/hooks/use-global-config.js"),b=require("../utils/is.js"),G=t.defineComponent({name:"EditableTableFormItem",__name:"form-item",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:{},onFieldChange:{},label:{},name:{},formItem:{default:()=>({})}},setup(f,{expose:g}){const o=f;j.useDevWarning("EditableTableFormItem")(!1,"breaking","EditableTableFormItem has been EOL, Please use EditableAgGridFormItem(https://aplus.aplnk.com/aplus-ui/components/ag-grid/editable/) instead.");const{internalInstance:i,model:h}=A.useInjectForm(),d=t.ref(P.getModelValue(t.unref(h),o.name)||[]),w=t.useSlots(),x=t.toRef(o,"name"),y=p.ApForm.useWatch(x);t.watch(()=>y.value,async e=>{await t.nextTick(),d.value=e,o.onChange?.(e)},{deep:!0});const{b:C}=K.useNamespace("editable-table"),R=_.default("editable-table"),m=t.shallowRef(),v=$.useGlobalConfig("valueTypeMap"),F=O.default(o,v);function q(e,l){const s=t.unref(d)?.length||0;if(b.isDef(o.maxLength)&&s>=o.maxLength)return;const n={...e||{}};i?.setFieldValue(o.name,n,!0,(a,r)=>{if(!a[r]){a[r]=[n];return}u.isUndefined(l)?a[r].push(n):a[r].splice(l,0,n)})}function B(e,l="suffix"){const s=t.unref(d)?.length||0,n=u.isNumber(e)?e:e.length;if(b.isDef(o.maxLength)&&s+n>o.maxLength)return;const a=u.isNumber(e)?new Array(e).fill(0).map(()=>({})):u.cloneDeep(e);i?.setFieldValue(o.name,a,!0,(r,c)=>{if(!r[c]){r[c]=[...a];return}l==="suffix"?r[c].push(...a):r[c].unshift(...a)})}function T(e){const l=new Set(u.isNumber(e)?[e]:e);i?.setFieldValue(o.name,void 0,!0,(s,n)=>{s[n]=s[n].filter((a,r)=>!l.has(r))})}function I(e){const l=new Set(u.isArray(e)?e:[e]);l.size!==0&&i?.setFieldValue?.(o.name,void 0,!0,(s,n)=>{s[n]=s[n].filter(a=>!l.has(a[o.rowKey]))})}function D(){return t.unref(d)}function S(e){return t.unref(d)?.[e]}function E(e,l,s=!0){i?.setFieldValue(o.name,void 0,!0,(n,a)=>{!n[a]||!n[a][e]||(n[a][e]={...s?n[a][e]:{},...l})})}function N(e){i?.setFieldValue(o.name,e)}function L(e,l){const s=e==="end"?d.value.length-1:e;z.scrollToRowIndex(s,m.value?.$el,l)}function V(){i?.setFieldValue?.(o.name,[])}return g({add:q,remove:T,getRowData:S,getRowsData:D,setRowData:E,addMultiple:B,scrollTo:L,setTableData:N,clear:V,removeByKey:I}),(e,l)=>(t.openBlock(),t.createBlock(t.unref(p.ApForm).FormItem,t.mergeProps(f.formItem,{name:f.name,label:f.label}),{default:t.withCtx(()=>[t.createVNode(t.unref(k.Table),t.mergeProps(t.unref(u.omit)(o,["name","maxLength","onChange"]),{ref_key:"tableRef",ref:m,class:[t.unref(C)(),t.unref(R)],columns:t.unref(F),"data-source":d.value}),t.createSlots({_:2},[t.renderList(t.unref(u.omit)(w,["headerCell"]),(s,n)=>({name:n,fn:t.withCtx(a=>[t.renderSlot(e.$slots,n,t.normalizeProps(t.guardReactiveProps(a||{})))])}))]),1040,["class","columns","data-source"])]),_:3},16,["name","label"]))}});exports.default=G;
