/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/has","../../../core/libs/rbush/PooledRBush","../../../geometry/support/aaBoundingRect"],(function(n,i,t,s,e){"use strict";const d=5e4,o={minX:0,minY:0,maxX:0,maxY:0};function h(n){o.minX=n[0],o.minY=n[1],o.maxX=n[2],o.maxY=n[3]}function u(n,i,t){h(i),n.search(o,t)}let a=function(){function n(){this._indexInvalid=!1,this._boundsToLoad=[],this._boundsById=new Map,this._idByBounds=new Map,this._index=new s.PooledRBush(9,t("esri-csp-restrictions")?n=>({minX:n[0],minY:n[1],maxX:n[2],maxY:n[3]}):["[0]","[1]","[2]","[3]"]),this._loadIndex=()=>{if(this._indexInvalid){const n=new Array(this._idByBounds.size);let i=0;this._idByBounds.forEach(((t,s)=>{n[i++]=s})),this._indexInvalid=!1,this._index.clear(),this._index.load(n)}else this._boundsToLoad.length&&(this._index.load(this._boundsToLoad.filter((n=>this._idByBounds.has(n)))),this._boundsToLoad.length=0)}}var o=n.prototype;return o.clear=function(){this._indexInvalid=!1,this._boundsToLoad.length=0,this._boundsById.clear(),this._idByBounds.clear(),this._index.clear()},o.delete=function(n){const i=this._boundsById.get(n);this._boundsById.delete(n),i&&(this._idByBounds.delete(i),this._indexInvalid||this._index.remove(i))},o.forEachInBounds=function(n,i){this._loadIndex(),u(this._index,n,(n=>i(this._idByBounds.get(n))))},o.get=function(n){return this._boundsById.get(n)},o.has=function(n){return this._boundsById.has(n)},o.invalidateIndex=function(){this._indexInvalid||(this._indexInvalid=!0,this._boundsToLoad.length=0)},o.set=function(n,i){if(!this._indexInvalid){const i=this._boundsById.get(n);i&&(this._index.remove(i),this._idByBounds.delete(i))}this._boundsById.set(n,i),i&&(this._idByBounds.set(i,n),this._indexInvalid||(this._boundsToLoad.push(i),this._boundsToLoad.length>d&&this._loadIndex()))},i._createClass(n,[{key:"fullBounds",get:function(){if(!this._boundsById.size)return null;const n=e.empty();for(const i of this._boundsById.values())i&&(n[0]=Math.min(i[0],n[0]),n[1]=Math.min(i[1],n[1]),n[2]=Math.max(i[2],n[2]),n[3]=Math.max(i[3],n[3]));return n}},{key:"valid",get:function(){return!this._indexInvalid}}]),n}();n.BoundsStore=a,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
