/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../chunks/_rollupPluginBabelHelpers","../../../core/Error","../../../core/Evented","../../../core/Logger","../../../core/maybe","../../../geometry/support/aaBoundingBox","../../../geometry/support/aaBoundingRect","../featureConversionUtils","./BoundsStore","./optimizedFeatureQueryEngineAdapter"],(function(e,t,r,s,o,n,i,u,d,a){"use strict";return function(){function h(e){this.geometryInfo=e,this._boundsStore=new d.BoundsStore,this._featuresById=new Map,this._markedIds=new Set,this.events=new r,this.featureAdapter=a.optimizedFeatureQueryEngineAdapter}var f=h.prototype;return f.add=function(e){this._add(e),this._emitChanged()},f.addMany=function(e){for(const t of e)this._add(t);this._emitChanged()},f.clear=function(){this._featuresById.clear(),this._boundsStore.clear(),this._emitChanged()},f.removeById=function(e){const t=this._featuresById.get(e);return t?(this._remove(t),this._emitChanged(),t):null},f.removeManyById=function(e){this._boundsStore.invalidateIndex();for(const t of e){const e=this._featuresById.get(t);e&&this._remove(e)}this._emitChanged()},f.forEachBounds=function(e,t,r){for(const s of e){const e=this._boundsStore.get(s.objectId);e&&t(n.fromRect(r,e))}},f.getFeature=function(e){return this._featuresById.get(e)},f.has=function(e){return this._featuresById.has(e)},f.toArray=function(){return Array.from(this._featuresById.values())},f.forEach=function(e){this._featuresById.forEach((t=>e(t)))},f.forEachInBounds=function(e,t){this._boundsStore.forEachInBounds(e,(e=>{t(this._featuresById.get(e))}))},f.startMarkingUsedFeatures=function(){this._boundsStore.invalidateIndex(),this._markedIds.clear()},f.sweep=function(){let e=!1;this._featuresById.forEach(((t,r)=>{this._markedIds.has(r)||(e=!0,this._remove(t))})),this._markedIds.clear(),e&&this._emitChanged()},f._emitChanged=function(){this.events.emit("changed",void 0)},f._add=function(e){if(!e)return;const r=e.objectId;if(null==r)return void s.getLogger("esri.layers.graphics.data.FeatureStore").error(new t("featurestore:invalid-feature","feature id is missing",{feature:e}));const n=this._featuresById.get(r);let d;if(this._markedIds.add(r),n?(e.displayId=n.displayId,d=this._boundsStore.get(r),this._boundsStore.delete(r)):o.isSome(this.onFeatureAdd)&&this.onFeatureAdd(e),o.isNone(e.geometry)||!e.geometry.coords||!e.geometry.coords.length)return this._boundsStore.set(r,null),void this._featuresById.set(r,e);d=u.getBoundsOptimizedGeometry(o.isSome(d)?d:i.create(),e.geometry,this.geometryInfo.hasZ,this.geometryInfo.hasM),o.isSome(d)&&this._boundsStore.set(r,d),this._featuresById.set(r,e)},f._remove=function(e){return o.isSome(this.onFeatureRemove)&&this.onFeatureRemove(e),this._markedIds.delete(e.objectId),this._boundsStore.delete(e.objectId),this._featuresById.delete(e.objectId),e},e._createClass(h,[{key:"geometryType",get:function(){return this.geometryInfo.geometryType}},{key:"hasM",get:function(){return this.geometryInfo.hasM}},{key:"hasZ",get:function(){return this.geometryInfo.hasZ}},{key:"numFeatures",get:function(){return this._featuresById.size}},{key:"fullBounds",get:function(){return this._boundsStore.fullBounds}},{key:"storeStatistics",get:function(){let e=0;return this._featuresById.forEach((t=>{o.isSome(t.geometry)&&t.geometry.coords&&(e+=t.geometry.coords.length)})),{featureCount:this._featuresById.size,vertexCount:e/(this.hasZ?this.hasM?4:3:this.hasM?3:2)}}}]),h}()}));
