/*
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/Evented","../../../../../core/maybe","./config","./core","./jobs","./SymbolDeclutterer","./SymbolRepository","./util","../style/StyleDefinition"],(function(t,e,i,s,o,l,r,a,n,c,_){"use strict";const u=.5,h=1e-6;let y=function(t){function i(e,i){var s;return(s=t.call(this)||this).styleRepository=e,s._tileToHandle=new Map,s._viewState={scale:0,rotation:0,center:[0,0],size:[0,0]},s._declutterViewState={scale:0,rotation:0,center:[0,0],size:[0,0]},s._completed=!1,s._symbolRepository=new n.SymbolRepository(4096,i,(()=>new l.VTLUniqueSymbol)),s._symbolDeclutterer=new a.SymbolDeclutterer(i,s._symbolRepository,((t,e,i)=>new r.CollisionJob(t,e,i,s.styleRepository,s._zoom,s._viewState.rotation)),((t,e)=>{t.allSymbolsFadingOut=!0,t.lastOpacityUpdate=e,c.writeOpacityToBuffers(t,e,!0),t.decluttered=!0,t.requestRender()}),((t,e)=>s.styleRepository.getStyleLayerByUID(t.styleLayerUID).z-s.styleRepository.getStyleLayerByUID(e.styleLayerUID).z),(t=>{const e=s.styleRepository.getStyleLayerByUID(t);if(s._zoom+h<e.minzoom||s._zoom-h>=e.maxzoom)return!1;const i=e.getLayoutProperty("visibility");return!i||i.getValue()!==_.Visibility.NONE})),s}e._inheritsLoose(i,t);var y=i.prototype;return y.addTile=function(t){t.decluttered=!1,this._tileToHandle.set(t,t.on("symbols-changed",(()=>{this._symbolRepository.add(t),this.restartDeclutter()}))),this._symbolRepository.add(t),this.restartDeclutter()},y.removeTile=function(t){const e=this._tileToHandle.get(t);e&&(this._symbolRepository.removeTile(t),this.restartDeclutter(),e.remove(),this._tileToHandle.delete(t))},y.update=function(t,e){return this._zoom=t,this._viewState={scale:e.scale,rotation:e.rotation,center:[e.center[0],e.center[1]],size:[e.size[0],e.size[1]]},this._continueDeclutter(),this._completed},y.restartDeclutter=function(){this._completed=!1,this._symbolDeclutterer.restart(),this._notifyUnstable()},y.clear=function(){this._completed=!1,this._symbolRepository=null,this._symbolDeclutterer.restart(),this._tileToHandle.forEach((t=>t.remove())),this._tileToHandle.clear()},y.deleteStyleLayers=function(t){this._symbolRepository.deleteStyleLayers(t)},y._continueDeclutter=function(){this._completed&&!this.stale||(this._symbolDeclutterer.running||(this._declutterZoom=this._zoom,this._declutterViewState.center[0]=this._viewState.center[0],this._declutterViewState.center[1]=this._viewState.center[1],this._declutterViewState.rotation=this._viewState.rotation,this._declutterViewState.scale=this._viewState.scale,this._declutterViewState.size[0]=this._viewState.size[0],this._declutterViewState.size[1]=this._viewState.size[1],this._symbolDeclutterer.restart()),this._symbolDeclutterer.setScreenSize(this._viewState.size[0],this._viewState.size[1]),this._completed=this._symbolDeclutterer.continue(o.DECLUTTER_BUDGET),this._completed&&this._scheduleNotifyStable())},y._scheduleNotifyStable=function(){s.isSome(this._stableNotificationHandle)&&clearTimeout(this._stableNotificationHandle),this._stableNotificationHandle=setTimeout((()=>{this._stableNotificationHandle=null,this.emit("fade-complete")}),(1+u)*o.FADE_DURATION)},y._notifyUnstable=function(){s.isSome(this._stableNotificationHandle)&&(clearTimeout(this._stableNotificationHandle),this._stableNotificationHandle=null),this.emit("fade-start")},e._createClass(i,[{key:"stale",get:function(){return this._zoom!==this._declutterZoom||this._viewState.size[0]!==this._declutterViewState.size[0]||this._viewState.size[1]!==this._declutterViewState.size[1]||this._viewState.scale!==this._declutterViewState.scale||this._viewState.rotation!==this._declutterViewState.rotation}}]),i}(i);t.SymbolFader=y,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
