/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{fromJSON as t}from"../../geometry/support/jsonUtils.js";import{convertFromGeometry as e}from"../graphics/featureConversionUtils.js";import{OptimizedFeature as r}from"../graphics/OptimizedFeature.js";import{systemOriginIdFieldName as o,systemDestinationIdFieldName as i}from"./constants.js";class s{constructor(){this._featureLookup=new Map}static getInstance(){return s.instance||(s.instance=new s),s.instance}static resetInstance(){s.instance&&(s.instance=null)}deleteFromStore(t){t.forEach(t=>{this._featureLookup.delete(t)})}readFromStoreByList(t){const e=[];return t.forEach(t=>{const r=this.readFromStoreById(t);r&&e.push(r)}),e}readFromStoreById(t){return this._featureLookup.get(t)??null}writeToStore(s,n,p){const a=[];return s.forEach(s=>{if(!s?.id)return;s.properties||(s.properties=[]);let u=null;p&&s.properties[p]&&(u=e(s.properties[p])),"originId"in s&&"destinationId"in s&&(s.properties[o]=s.originId,s.properties[i]=s.destinationId),s.properties[n]=s.id;let c=s.properties;if(s.id){const e=this._featureLookup.get(s.id);if(e?.attributes){c={...e.attributes,...c};const r=p&&c[p];null!=r&&(c[p]=t(r)),u=u??e.geometry}}const d=new r(u?.clone(),c,null,s.id);this._featureLookup.set(`${s.typeName?`${s.typeName}__${s.id}`:s.id}`,d),a.push(d)}),a}}export{s as default};
