/*
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/Handles","../../../../core/maybe","../../../../core/PooledArray","./basicInterfaces","./ContentObject","./ContentObjectType","./DirtyEvents","./Octree"],(function(e,t,i,s,n,o,r,a,c,l,h){"use strict";let d=function(e){function a(t,n=""){var a,l,h,d;return(d=e.call(this)||this).apiLayerUid=n,d.type=c.ContentObjectType.Layer,d.events=new i,d.isSliceable=!1,d._objects=new o,d._stageHandles=new s,d.apiLayerUid=n,d.isVisible=null==(a=null==t?void 0:t.isVisible)||a,d.isPickable=null==(l=null==t?void 0:t.isPickable)||l,d.updatePolicy=null!=(h=null==t?void 0:t.updatePolicy)?h:r.UpdatePolicy.ASYNC,d}t._inheritsLoose(a,e);var d=a.prototype;return d.destroy=function(){this.detachStage(),this._stage=null},d.attachStage=function(e){this.detachStage(),this._stage=e;for(const t of l.DirtyEventNames)this._stageHandles.add(this.events.on(t,(i=>e.handleEvent(t,i))))},d.detachStage=function(){this._stageHandles.removeAll(),this.invalidateSpatialQueryAccelerator()},d.add=function(e){this._objects.push(e),e.parentLayer=this,this.events.emit("layerObjectAdded",{layer:this,object:e}),n.isSome(this._octree)&&this._octree.add([e])},d.remove=function(e){this._objects.removeUnordered(e)&&(e.parentLayer=null,this.events.emit("layerObjectRemoved",{layer:this,object:e}),n.isSome(this._octree)&&this._octree.remove([e]))},d.addMany=function(e){this._objects.pushArray(e);for(const t of e)t.parentLayer=this;this.events.emit("layerObjectsAdded",{layer:this,objects:e}),n.isSome(this._octree)&&this._octree.add(e)},d.removeMany=function(e){const t=new Array;if(this._objects.removeUnorderedMany(e,e.length,t),0!==t.length){for(const e of t)e.parentLayer=null;this.events.emit("layerObjectsRemoved",{layer:this,objects:t}),n.isSome(this._octree)&&this._octree.remove(t)}},d.sync=function(){n.isSome(this._stage)&&this.updatePolicy!==r.UpdatePolicy.SYNC&&this._stage.syncLayer(this.id)},d.notifyObjectBBChanged=function(e,t){n.isSome(this._octree)&&this._octree.update(e,t)},d.getSpatialQueryAccelerator=function(){return n.isNone(this._octree)&&this._objects.length>50&&this._createOctree(),this._octree},d.shaderTransformationChanged=function(){this.invalidateSpatialQueryAccelerator(),this.events.emit("shaderTransformationChanged",this)},d.invalidateSpatialQueryAccelerator=function(){this._octree=n.destroyMaybe(this._octree)},d._createOctree=function(){this._octree=new h((e=>e.boundingVolumeWorldSpace.bounds)),this._octree.add(this._objects.data,this._objects.length)},t._createClass(a,[{key:"objects",get:function(){return this._objects}}]),a}(a.ContentObject);function u(e){return n.isSome(e)&&e.type===c.ContentObjectType.Layer}e.WebGLLayer=d,e.isWebGLLayer=u,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
