"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),d=require("element-plus"),F=require("./types.js"),I=require("../../../pro-table/index.js"),j=require("./columns-item.vue.js"),E=require("../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/cloneDeep.js");function q(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!t.isVNode(n)}const O=t.defineComponent({name:"WetEditableTabl",props:{...F.wetEditTableProps},emits:["update:modelValue","change"],setup(n,{emit:o,expose:_}){const h=d.useNamespace("editable-table"),r=t.ref([]),b=t.shallowRef(),c=t.useSlots(),C=(l,e)=>{const a=[...n.modelValue||[]];o("update:modelValue",a),n.controlled||o("change",{row:l,$index:e})},k=(l,e)=>{o("change",{row:l,$index:e})},s=(l=!1)=>{const e=n.modelValue||[],a=E.default(n.addDefaultRow);let u=e.length;n.controlled&&r.value.push(a),l?(e.unshift(a),u=0):e.push(a),o("update:modelValue",e),o("change",{row:a,$index:u})},p=l=>{r.value=r.value.filter(e=>e!==l)},f=l=>{if(n.modelValue&&n.modelValue.length>l){const e=[...n.modelValue],a=e.splice(l,1);p(a),o("update:modelValue",e),o("change",{row:null,$index:l})}},V=(l,e)=>{const a=[...n.modelValue||[]],u=E.default(l);e!==void 0?a.splice(e+1,0,u):a.push(u),o("update:modelValue",a),o("change",{row:u,$index:e||a.length})},g=l=>{r.value.includes(l)||r.value.push(l)},v=t.shallowRef(!1),y=l=>{v.value||(p(l),v.value=!0,setTimeout(()=>{v.value=!1},200))},m=l=>p(l),B=(l,e)=>{var u;const a=(u=n.modelValue)==null?void 0:u[l];a&&(Object.assign(a,e),o("update:modelValue",n.modelValue),o("change",{row:a,$index:l}))},P={placement:"top"},x=(l,e,a)=>{let u;return t.createVNode(d.ElSpace,{size:l.length===0?0:void 0},q(u=l.map(i=>i==="add"?t.createVNode(d.ElButton,{link:!0,type:"primary",onClick:()=>s()},{default:()=>[t.createTextVNode("新增")]}):i==="delete"?t.createVNode(d.ElPopconfirm,t.mergeProps(P,{title:"删除此项？",onConfirm:()=>f(a)}),{reference(){return t.createVNode(d.ElButton,{link:!0,type:"danger"},{default:()=>[t.createTextVNode("删除")]})}}):i==="copy"?t.createVNode(d.ElButton,{link:!0,type:"primary",onClick:()=>V(e,a)},{default:()=>[t.createTextVNode("复制")]}):i==="edit"?t.createVNode(t.Fragment,null,[r.value.includes(e)?t.createVNode(t.Fragment,null,[t.createVNode(d.ElButton,{link:!0,type:"primary",onClick:()=>y(e)},{default:()=>[t.createTextVNode("保存")]}),t.createVNode(d.ElButton,{link:!0,type:"primary",onClick:()=>m(e)},{default:()=>[t.createTextVNode("取消")]})]):t.createVNode(d.ElButton,{link:!0,type:"primary",onClick:()=>g(e)},{default:()=>[t.createTextVNode("编辑")]})]):void 0))?u:{default:()=>[u]})},S=l=>n.readonly?!0:r.value.includes(l)?!1:n.controlled,D=t.computed(()=>(n.columns||[]).filter(e=>n.readonly?e.valueType!=="actions":e).map(e=>({...e,isRender:!1,render({row:a,$index:u}){var i,T;if(e.valueType==="actions")return e.isRender?c.actions&&c.actions({row:a,$index:u,actions:{add:s,deleteRow:f,saveRow:y,copy:V,cancel:m,edit:g,readonly:!r.value.includes(a)}}):e.render?e.render({row:a,$index:u},{add:s,deleteRow:f,saveRow:y,copy:V,cancel:m,edit:g,readonly:r.value.includes(a)}):x(e.actions||[],a,u);{const R=Array.isArray(e.dataIndex)?e.dataIndex.join(""):e.dataIndex;let N=a&&e.render;return e.isRender&&a&&(N=c[R]&&c[R]),t.createVNode(j.default,{row:a,index:u,prop:n.prop,itemConfig:{...e,fieldProps:{...e.fieldProps||{},disabled:n.disabled||((i=e.fieldProps)==null?void 0:i.disabled),clearable:n.clearable||((T=e.fieldProps)==null?void 0:T.clearable)}},changeValue:C,emitControlChangeValue:k,readonly:S(a),controlled:n.controlled,saveTag:v.value},{default:N?()=>N({$index:u,row:a}):null})}}})));return _({scrollToIndex:l=>{var e;return(e=b.value)==null?void 0:e.scrollToIndex(l)},add:s,deleteRow:f,saveRow:y,copy:V,cancel:m,edit:g,setRowData:B}),()=>t.createVNode("div",{class:h.b()},[c.header&&t.createVNode("div",{class:h.e("header")},[c.header({addBefore:()=>s(!0),add:()=>s(),deleteRow:f,copy:V})]),t.createVNode(I.WetSchemaTable,t.mergeProps({...n,modelValue:"",adddefaultrow:""},{ref:b,data:n.modelValue||[],columns:D.value}),null),c.footer&&t.createVNode("div",{class:h.e("footer")},[c.footer({addBefore:()=>s(!0),add:()=>s(),deleteRow:f,copy:V})])])}});exports.default=O;
