/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import r from"../../../../core/Accessor.js";import{destroyHandle as t}from"../../../../core/handleUtils.js";import{removeMaybe as o,abortMaybe as i}from"../../../../core/maybe.js";import{isAborted as s}from"../../../../core/promiseUtils.js";import{property as n,subclass as a}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as d}from"../../../../core/support/UpdatingHandles.js";import{EdgeWorkerHandle as l}from"../../../3d/webgl-engine/lib/edgeRendering/EdgeWorkerHandle.js";import{SceneLayerSnappingSourceWorkerHandle as c}from"./sceneLayerSource/SceneLayerSnappingSourceWorkerHandle.js";let p=class extends r{get updating(){return this._updatingHandles.updating}constructor(e){super(e),this.availability=1,this._updatingHandles=new d,this._abortController=new AbortController}destroy(){this._tracker=o(this._tracker),this._abortController=i(this._abortController),this._updatingHandles.destroy()}initialize(){const{view:e}=this,r=e.resourceController;this._edgeWorker=new l(h(r)),this._workerHandle=new c({renderCoordsHelper:this.view.renderCoordsHelper,schedule:h(r),fetchEdgeLocations:async(e,r)=>{if(null==this._tracker)throw new Error("tracker-not-initialized");return this._tracker.fetchEdgeLocations(e,this._edgeWorker,r)}}),this._updatingHandles.consumePromise(this._setupLayerView()),this.addHandles([t(this._workerHandle),t(this._edgeWorker)])}async fetchCandidates(e,r){return this._workerHandle.fetchCandidates(e,r)}refresh(){}async _setupLayerView(){if(this.destroyed)return;const e=this._abortController?.signal,r=await this.getLayerView();null==r||s(e)||(this._tracker=r.trackSnappingSources({add:(r,t)=>this._updatingHandles.consumePromise(this._workerHandle.add({id:r,bounds:t.toJSON()},e)),remove:r=>this._updatingHandles.consumePromise(this._workerHandle.remove({id:r},e))}))}};function h(e){return r=>e.immediate.schedule(r)}e([n({constructOnly:!0})],p.prototype,"getLayerView",void 0),e([n({constructOnly:!0})],p.prototype,"view",void 0),e([n({readOnly:!0})],p.prototype,"updating",null),e([n({readOnly:!0})],p.prototype,"availability",void 0),p=e([a("esri.views.interactive.snapping.featureSources.I3SSnappingSource")],p);export{p as I3SSnappingSource};
