globalThis.jotaiAtomCache=globalThis.jotaiAtomCache||{cache:new Map,get(n,a){return this.cache.has(n)?this.cache.get(n):(this.cache.set(n,a),a)}};function f(n,a){var i,t,u;for(const{db:p,id:d}of a){const l=(t=(i=n.db)==null?void 0:i.modelDefined)==null?void 0:t[d],o=(u=n.db)==null?void 0:u[p];l===void 0&&o===void 0||n.setComponent(d,r=>{l!==void 0&&(r.modelDefined=l),o!==void 0&&(r.value=o)})}}const g=n=>({$:a,e:i})=>{a.setThisComponent(t=>{t.value=i}),a.setDb(t=>{t[n]=i})},v=({$:n,componentId:a,dbKey:i,fields:t,mapFieldKey:u,mapFieldValue:p})=>{var m;const d=((m=n.db)==null?void 0:m[i])||[],l=new Map(d.map(e=>[e[0].value,e])),o=[],r=[];t==null||t.forEach(e=>{const s=l.get(e.value);if(s&&l.delete(e.value),!e.required){s&&(s[0].disabled=!1,r.push(s));return}if(s){s[0].disabled=!0,o.push(s);return}o.push([{disabled:!0,name:u,value:e.value},{name:p,required:!0,value:[]}])});const c=[...o,...r];if(l.size)for(const e of l.values())e[0].disabled=!1,c.push(e);const h=o.length?Array.from({length:o.length},(e,s)=>s):[];return n.setComponent(a,e=>{n.util.isRepeaterFieldComponent(e)&&(e.value=c,e.nonRemovableRows=h)}),n.setDb(e=>{e[i]=c,e.nonRemovableRows=h}),{repeaterValue:c,requiredFieldIndexes:h}};export{v as a,g as h,f as s};
