/*
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/Accessor","../../../core/Collection","../../../core/maybe","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../../geometry/support/vectorStacks","../../../layers/graphics/data/QueryEngineResult","./FeatureSnappingLayerSource","./snappingUtils","./featureSources/SceneLayerSnappingSource","../support/viewUtils"],(function(e,n,t,r,i,o,s,a,p,c,u,l,S,y,g,d,_){"use strict";e.SceneSnappingEngine=function(e){function t(n){var t;return(t=e.call(this,n)||this).options=null,t._snappingSources=new i,t}n._inheritsLoose(t,e);var r=t.prototype;return r.initialize=function(){this.own([this.view.on("layerview-create",(({layerView:e})=>this._createSource(e))),this.view.on("layerview-destroy",(({layerView:e})=>this._removeSource(e)))]);for(const e of this.view.allLayerViews.items)this._createSource(e)},r.destroy=function(){this.options=null,this._snappingSources.drain((e=>e.destroy()))},r.fetchCandidates=function(){var e=n._asyncToGenerator((function*(e,n,t){const{view:r,options:i}=this,{coordinateHelper:s,elevationInfo:a}=n,p=o.isSome(i)?i.distance:1,c=_.anyMapPointToRender(e,s,a,r,l.sv3d.get()),u=p*r.state.camera.computeScreenPixelSizeAt(c),S=this._types,y=this._snappingSources.items.map((n=>n.fetchCandidates({point:e,coordinateHelper:s,distance:u,types:S},t))),d=(yield Promise.all(y)).flat();return g.sortCandidatesInPlace(e,d),d}));function t(n,t,r){return e.apply(this,arguments)}return t}(),r._createSource=function(e){if("scene-layer-3d"!==e.type)return;const n=new d.SceneLayerSnappingSource({layerSource:new y({layer:e.layer}),view:this.view});this._snappingSources.push(n)},r._removeSource=function(e){const n=this._snappingSources.findIndex((n=>n.layerSource.layer===e.layer));-1!==n&&this._snappingSources.removeAt(n).destroy()},n._createClass(t,[{key:"updating",get:function(){return this._snappingSources.some((e=>e.updating))}},{key:"_types",get:function(){return S.SnappingTypes.EDGE|S.SnappingTypes.VERTEX}}]),t}(r),t.__decorate([s.property({constructOnly:!0})],e.SceneSnappingEngine.prototype,"view",void 0),t.__decorate([s.property()],e.SceneSnappingEngine.prototype,"updating",null),t.__decorate([s.property()],e.SceneSnappingEngine.prototype,"options",void 0),t.__decorate([s.property()],e.SceneSnappingEngine.prototype,"_snappingSources",void 0),e.SceneSnappingEngine=t.__decorate([u.subclass("esri.views.interactive.snapping.SceneSnappingEngine")],e.SceneSnappingEngine),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
