/*
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/HandleOwner","../../../../core/handleUtils","../../../../core/maybe","../../../../core/reactiveUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../2d/interactive/snapping/featureSources/featureServiceSource/FeatureServiceTiles2D","../../../3d/interactive/snapping/featureSources/featureServiceSource/FeatureServiceTiles3D","./queryEngineUtils","./WorkerTileTreeDebugger","./featureServiceSource/FeatureServiceSnappingSourceWorkerHandle","./featureServiceSource/FeatureServiceTilesSimple","../../../support/debugFlags"],(function(e,r,t,i,a,n,o,s,l,u,c,p,d,S,h,y,g,f,v,w){"use strict";e.FeatureServiceSnappingSource=function(e){function t(r){return e.call(this,r)||this}r._inheritsLoose(t,e);var i=t.prototype;return i.initialize=function(){const e=this.view;if(o.isSome(e))switch(e.type){case"2d":this.tilesOfInterest=new S.FeatureServiceTiles2D({view:e,layer:this.layer}),this.workerHandle=new f.FeatureServiceSnappingSourceWorkerHandle;break;case"3d":{const r=e.resourceController;this.tilesOfInterest=new h.FeatureServiceTiles3D({view:e}),this.workerHandle=new f.FeatureServiceSnappingSourceWorkerHandle({schedule:e=>r.schedule(e)});break}}else this.tilesOfInterest=new v.FeatureServiceTilesSimple({layer:this.layer}),this.workerHandle=new f.FeatureServiceSnappingSourceWorkerHandle;this.handles.add([n.destroyHandle(this.workerHandle)]),this.workerHandle.setup({layer:this.layer,spatialReference:this.spatialReference,configuration:this.configuration},null),this.updatingHandles.add((()=>this.updateTilesParameters),(()=>this.workerHandle.updateTiles(this.updateTilesParameters,null)),s.initial),this.handles.add([s.watch((()=>this.configuration),(e=>this.workerHandle.configure(e,null)),s.sync)]),o.isSome(e)&&this.handles.add(s.watch((()=>w.FEATURE_SERVICE_SNAPPING_SOURCE_TILE_TREE_SHOW_TILES),(r=>{r&&!this.debug?(this.debug=new g.WorkerTileTreeDebugger({view:e,handle:this.workerHandle}),this.handles.add(n.destroyHandle(this.debug),"debug")):!r&&this.debug&&this.handles.remove("debug")}),s.initial)),this.handles.add(this.layerSource.layer.on("apply-edits",(e=>{this.workerHandle.applyEdits(e,null)})))},i.refresh=function(){this.workerHandle.refresh(null)},i.fetchCandidates=function(){var e=r._asyncToGenerator((function*(e,r){return this.tilesOfInterest.pointOfInterest=e.coordinateHelper.vectorToPoint(e.point),(yield this.workerHandle.fetchCandidates({...e,filter:null},r)).candidates.map((r=>y.convertSnappingCandidate(r,e.coordinateHelper,e.elevationInfo)))}));function t(r,t){return e.apply(this,arguments)}return t}(),i.getDebugInfo=function(e){return this.workerHandle.getDebugInfo(e)},r._createClass(t,[{key:"updateTilesParameters",get:function(){return{tiles:this.tilesOfInterest.tiles,tileInfo:this.tilesOfInterest.tileInfo,tileSize:this.tilesOfInterest.tileSize}}},{key:"updating",get:function(){return this.workerHandle.updating||this.updatingHandles.updating}},{key:"configuration",get:function(){return{filter:this.layer.createQuery(),customParameters:this.layer.customParameters}}},{key:"availability",get:function(){return this.workerHandle.availability}},{key:"layer",get:function(){return this.layerSource.layer}}]),t}(a.HandleOwnerMixin(i)),t.__decorate([l.property({constructOnly:!0})],e.FeatureServiceSnappingSource.prototype,"spatialReference",void 0),t.__decorate([l.property({constructOnly:!0})],e.FeatureServiceSnappingSource.prototype,"layerSource",void 0),t.__decorate([l.property({constructOnly:!0})],e.FeatureServiceSnappingSource.prototype,"view",void 0),t.__decorate([l.property()],e.FeatureServiceSnappingSource.prototype,"tilesOfInterest",void 0),t.__decorate([l.property({readOnly:!0})],e.FeatureServiceSnappingSource.prototype,"updateTilesParameters",null),t.__decorate([l.property({readOnly:!0})],e.FeatureServiceSnappingSource.prototype,"updating",null),t.__decorate([l.property({readOnly:!0})],e.FeatureServiceSnappingSource.prototype,"configuration",null),t.__decorate([l.property({readOnly:!0})],e.FeatureServiceSnappingSource.prototype,"availability",null),e.FeatureServiceSnappingSource=t.__decorate([d.subclass("esri.views.interactive.snapping.featureSources.FeatureServiceSnappingSource")],e.FeatureServiceSnappingSource),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
