"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("lodash-unified"),v=require("vue");require("../../utils/index.js");const E=require("../../utils/warning.js"),K=require("../../utils/is.js");let N=0;function R(){return`_ag_grid${N++}`}const T=(u,y,i,h)=>{const m=E.useDevWarning("EditableAgGrid"),w=v.shallowRef([]),x=v.computed(()=>v.isRef(y)?v.unref(y):y);function I(e,t){const o=v.unref(i)?.length||0;if(K.isDef(u.maxLength)&&o>=u.maxLength||!e&&c.isFunction(u.rowKey))return;const r={...e||{[u.rowKey]:R()}};if(!i.value){i.value=[r];return}c.isUndefined(t)?i.value.push(r):(w.value=i.value.map((n,s)=>s<t?null:l(n,s,u.rowKey)).filter(Boolean),i.value.splice(t,0,r))}function F(e,t){const o=v.unref(i)?.length||0;if(K.isDef(u.maxLength)&&o>=u.maxLength||!e&&c.isFunction(u.rowKey))return;const r={...e||{[u.rowKey]:R()}};if(!i.value){i.value=[r];return}const n=i.value.findIndex((f,d)=>l(f,d,u.rowKey)===t),s=c.isUndefined(t)||n===-1||n===i.value?.length-1?void 0:n+1;c.isUndefined(s)?i.value.push(r):(w.value=i.value.map((f,d)=>d<s?null:l(f,d,u.rowKey)).filter(Boolean),i.value.splice(s,0,r))}function B(e,t="suffix"){const o=v.unref(i)?.length||0,r=c.isNumber(e)?e:e.length;if(K.isDef(u.maxLength)&&o+r>u.maxLength||c.isNumber(e)&&c.isFunction(u.rowKey))return;const n=c.isNumber(e)?new Array(e).fill(0).map(()=>({[u.rowKey]:R()})):c.cloneDeep(e);if(!i.value){i.value=[...n];return}t==="suffix"?i.value.push(...n):(w.value=i.value.map((s,f)=>l(s,f,u.rowKey)),i.value.unshift(...n))}function U(e){const t=c.isArray(e)?e:[e],o=i.value.filter(n=>!t.includes(n)),r=i.value.findIndex(n=>t.includes(n));w.value=i.value.map((n,s)=>s<=r?null:l(n,s,u.rowKey)).filter(Boolean),h?.(o)}function l(e,t,o){if(o)return c.isString(o)?e[o]:o(e,t)}function L(e){const t=new Set(c.isArray(e)?e:[e]);if(t.size===0)return;const o=i.value.filter((n,s)=>!t.has(l(n,s,u.rowKey))),r=i.value.findIndex((n,s)=>t.has(l(n,s,u.rowKey)));w.value=i.value.map((n,s)=>s<=r?null:l(n,s,u.rowKey)).filter(Boolean),h?.(o)}function A(e){return m(!u.supressForceRowUpdate,"usage",'Avoid using getRowData/setRowData methods while suppressForceRowUpdate is enabled."'),v.unref(i)?.[e]}function j(e){return i.value?.find((t,o)=>l(t,o,u.rowKey)===e)}function q(){return v.unref(i)}function O(e,t,o=!0){m(!u.supressForceRowUpdate,"usage",'Avoid using getRowData/setRowData methods while suppressForceRowUpdate is enabled."'),x.value?.setFieldValue?.(u.name,void 0,!0,(r,n)=>{const s=i.value.findIndex((d,g)=>e===g);if(!~s)return;const f=l(i.value[s],s,u.rowKey);if(f&&!(!r[n]||!r[n][f])){if(!o){const d=Object.keys(r[n][f]);for(const g of d)g!==u.rowKey&&delete r[n][f][g]}Object.assign(r[n][f],{...t})}})}function S(e,t,o=!0){x.value?.setFieldValue?.(u.name,void 0,!0,(r,n)=>{if(!(!r[n]||!r[n][e])){if(!o){const s=Object.keys(r[n][e]);for(const f of s)f!==u.rowKey&&delete r[n][f][f]}Object.assign(r[n][e],{...t})}})}function k(){h?.([])}return{add:I,addByKey:F,addMultiple:B,remove:U,removeByKey:L,getRowData:A,getRowsData:q,setRowDataByKey:S,setRowData:O,clear:k,refreshRowIds:w,getRowDataByKey:j}};exports.useEditableApi=T;
