/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{TileCombinedCoverage as s}from"./TileCombinedCoverage.js";function e(s,e){const t=new Set;for(const i of s instanceof Set?s.values():s.keys())e.has(i)||t.add(i);return t}class t{constructor(s){this.version=s}}class i{constructor(s){this._tileInfoView=s,this._subscriptions=new Map,this._version=0}destroy(){}get coverage(){return this._coverage}get subscriptions(){return new Set(this._subscriptions.keys())}suspend(s){this._suspendedCoverage=this._coverage,this._coverage=null,this._updateSubscriptions(s)}resume(s){null==this._coverage&&(this._coverage=this._suspendedCoverage,this._suspendedCoverage=null,this._updateSubscriptions(s))}update(e,t,i){return this._version=(this._version+1)%Number.MAX_SAFE_INTEGER,this._coverage=new s(this._tileInfoView,e,t),this._updateSubscriptions(i)}_updateSubscriptions(s){if(!this._coverage)return null;const i=new Set(Array.from(this._coverage.values()).map(s=>s.id)),r=e(this._subscriptions,s),o=e(i,this._subscriptions),n=e(r,i);for(const e of o.values())this._subscriptions.set(e,new t(this._version));for(const e of n.values())this._subscriptions.delete(e);if(o.size||n.size){return{subscribe:Array.from(o.values()).map(s=>({tileId:s,version:this._subscriptions.get(s).version})),unsubscribe:Array.from(n.values())}}return null}}export{i as FeatureTileSubscriptionManager};
