/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import t from"../../../../../core/Accessor.js";import{property as r,subclass as o}from"../../../../../core/accessorSupport/decorators.js";import{create as n}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{WorkerHandle as i}from"../../../../../core/workers/WorkerHandle.js";import{markAsTarget as s,fromVec3 as d}from"../../../sketch/normalizedPoint.js";import{EdgeSnappingCandidate as a}from"../../candidates/EdgeSnappingCandidate.js";import{VertexSnappingCandidate as c}from"../../candidates/VertexSnappingCandidate.js";let l=class extends t{constructor(e){super(e),this.availability=0,this._ids=new Set}destroy(){this._workerHandle.destroy(),this._workerHandle=null}initialize(){this._workerHandle=new p(this.schedule,{fetchAllEdgeLocations:(e,t)=>this._fetchAllEdgeLocations(e,t)})}async fetchCandidates(e,t){const r=e.coordinateHelper,{point:o}=e,i=n();if(!this.renderCoordsHelper.toRenderCoords(o,r.spatialReference,i))return[];const s=e.distance,d="number"==typeof s?s:s.distance,a=await this._workerHandle.invoke({mbsJSON:{center:i,radius:d},returnEdge:e.returnEdge,returnVertex:"none"!==e.vertexMode},t);return a.candidates.sort((e,t)=>e.distance-t.distance),a.candidates.map(e=>this._convertCandidate(r,e))}async add(e,t){this._ids.add(e.id),await this._workerHandle.invokeMethod("add",e,t)}async remove(e,t){this._ids.delete(e.id),await this._workerHandle.invokeMethod("remove",e,t)}_convertCandidate(e,t){switch(t.type){case"edge":return new a({objectId:t.objectId,targetPoint:s(this._convertRenderCoordinate(e,t.target)),edgeStart:this._convertRenderCoordinate(e,t.start),edgeEnd:this._convertRenderCoordinate(e,t.end),isDraped:!1});case"vertex":return new c({objectId:t.objectId,targetPoint:s(this._convertRenderCoordinate(e,t.target)),isDraped:!1})}}_convertRenderCoordinate({spatialReference:e},t){const r=n();return this.renderCoordsHelper.fromRenderCoords(t,r,e),d(r)}async _fetchAllEdgeLocations(e,t){const r=[],o=[];for(const{id:n,uid:i}of e.components)this._ids.has(n)&&r.push((async()=>{const e=await this.fetchEdgeLocations(n,t.signal),r=e.locations.buffer;return o.push(r),{id:n,uid:i,objectIds:e.objectIds,locations:r,origin:e.origin,type:e.type}})());return{result:{components:(await Promise.all(r)).filter(({id:e})=>this._ids.has(e))},transferList:o}}};e([r({constructOnly:!0})],l.prototype,"renderCoordsHelper",void 0),e([r({constructOnly:!0})],l.prototype,"fetchEdgeLocations",void 0),e([r({constructOnly:!0})],l.prototype,"schedule",void 0),e([r({readOnly:!0})],l.prototype,"availability",void 0),l=e([o("esri.views.interactive.snapping.featureSources.sceneLayerSource.SceneLayerSnappingSourceWorkerHandle")],l);class p extends i{constructor(e,t){super("SceneLayerSnappingSourceWorker","fetchCandidates",{},e,{strategy:"dedicated",client:t})}}export{l as SceneLayerSnappingSourceWorkerHandle};
