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