/*
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","../../../../chunks/tslib.es6","../../../../core/Handles","../../../../core/MapUtils","../../../../core/maybe","../../../../core/reactiveUtils","../../../../core/Logger","../../../../core/accessorSupport/ensureType","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/set","../../../../core/accessorSupport/decorators/subclass","../../../../chunks/boundedPlane","./Deconflictor","./enums","./LabelDeconflictor","../../../support/Scheduler"],(function(e,t,i,s,a,n,r,c,o,l,h,u,p,d,f,_,g,y){"use strict";function b(e){const t=e.layer;return!(!t||!t.featureReduction||"selection"!==t.featureReduction.type)}function v(e){const t=e.graphics3DGraphics;t&&t.forEach((e=>e.clearVisibilityFlag(_.VisibilityFlag.DECONFLICTION)))}e.GraphicsDeconflictor=function(e){function i(){var t;return(t=e.apply(this,arguments)||this)._handles=new s,t._contexts=new Map,t._viewState=new f.DeconflictorViewState,t.visibilityGroup=_.VisibilityGroup.GRAPHIC,t._iconMarginFactor=-.1,t}t._inheritsLoose(i,e);var c=i.prototype;return c.initialize=function(){this._handles.add([r.watch((()=>{var e,t;return null==(e=this.view)||null==(t=e.state)?void 0:t.camera}),(()=>{this._updateViewState(),this.setDirty()})),r.watch((()=>{var e,t,i;return null==(e=this.view)||null==(t=e.map)||null==(i=t.ground)?void 0:i.opacity}),((e,t)=>{1!==e&&1!==t||this.setDirty()})),r.watch((()=>{var e;return null==(e=this.view)?void 0:e.slicePlane}),(()=>{this._updateSlicePlane(),this._slicePlaneChanged()}),r.initial)]),this._frameTask=this.view.resourceController.scheduler.registerTask(y.TaskPriority.GRAPHICS_DECONFLICTOR,this),this._labels=new g.LabelDeconflictor({view:this.view,parent:this})},c.destroy=function(){this._labels.destroy(),this._labels=null,this._handles.destroy(),this._handles=null,this._frameTask&&(this._frameTask.remove(),this._frameTask=null)},c.setDirty=function(){this._contexts.size>0&&(e.prototype.setDirty.call(this),this._labels.setDirty())},c.runTask=function(t){e.prototype.runTask.call(this,t),this.running||this._labels.setDirty()},c.setInitialIconVisibilityFlag=function(e,t){const i=!(this._graphicSupportsDeconfliction(t)&&b(e));t.setVisibilityFlag(_.VisibilityFlag.DECONFLICTION,i,_.VisibilityGroup.GRAPHIC)},c._updateViewState=function(){this.view&&this.view.state&&(this._viewState.camera.copyFrom(this.view.state.camera),this._updateSlicePlane())},c._updateSlicePlane=function(){const e=this.view?this.view.slicePlane:null;n.isSome(e)&&d.transform(e,this._viewState.camera.viewMatrix,this._viewState.slicePlane),this._viewState.slicePlaneEnabled=n.isSome(e)},c._slicePlaneChanged=function(){a.someMap(this._contexts,((e,t)=>t.symbolCreationContext.slicePlaneEnabled))&&this.setDirty()},c.addGraphicsOwner=function(e){let t=this._contexts.get(e);return null==t&&(t=new Map,this._contexts.set(e,t),this.setDirty()),{addGraphic:i=>this._addGraphic(e,t,i),removeGraphic:e=>this._removeGraphic(t,e),labelingInfoChange:()=>this._labels.enabledChanged(e,t),featureReductionChange:()=>this.enabledChanged(e,t),slicePlaneEnabledChange:()=>this._slicePlaneEnabledChanged(e,t),clear:()=>t.forEach((e=>this._removeGraphic(t,e.graphics3DGraphic)))}},c.removeGraphicsOwner=function(e){const t=this._contexts.get(e);t&&(t.forEach((e=>this._removeGraphic(t,e.graphics3DGraphic))),this._contexts.delete(e),this.setDirty())},c._addGraphic=function(e,t,i){const s=i.graphic.uid,a=new f.DeconflictorGraphic(i,e.symbolCreationContext.slicePlaneEnabled);t.set(s,a),b(e)&&this.addToActiveGraphics(a),e.labelsEnabled&&this._labels.addToActiveGraphics(a)},c._removeGraphic=function(e,t){const i=t.graphic.uid,s=e.get(i);s&&(this.removeFromActiveGraphics(s),this._labels.removeFromActiveGraphics(s),e.delete(i),this.setDirty())},c.enabledChanged=function(e,t){const i=b(e);i||v(e),this.modifyGraphics(t,i)},c._slicePlaneEnabledChanged=function(e,t){const i=e.symbolCreationContext.slicePlaneEnabled;t.forEach((e=>e.slicePlaneEnabled=i)),this.setDirty()},c.getGraphicsLayers=function(e){return e.graphics},c._graphicSupportsDeconfliction=function(e){if(e.isDraped)return!1;const t=e.graphics;if(!t||!t.length)return!1;for(const i of t)if(this.layerSupportsDeconfliction(i))return!0;return!1},t._createClass(i,[{key:"labels",get:function(){return this._labels}},{key:"viewState",get:function(){return this._viewState}},{key:"iconMarginFactor",get:function(){return this._iconMarginFactor},set:function(e){this._iconMarginFactor=e,this.setDirty()}}]),i}(f.Deconflictor),e.GraphicsDeconflictor=i.__decorate([p.subclass("esri.views.3d.layers.graphics.GraphicsDeconflictor")],e.GraphicsDeconflictor),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
