/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t}from"tslib";import s from"../../../core/Accessor.js";import{abortMaybe as o,removeMaybe as n}from"../../../core/maybe.js";import{debounce as i}from"../../../core/promiseUtils.js";import{property as e,subclass as r}from"../../../core/accessorSupport/decorators.js";import{ImmediateTask as a,TaskPriority as l}from"../../support/Scheduler.js";let p=class extends s{constructor(t){super(t),this.constrainResult=t=>t,this._snapPoints=null,this._frameTask=null,this._abortController=null,this._stagedPoint=null,this._snap=i(async(t,s,o,n)=>{const i=this._frameTask;if(null==i)return;const e=await i.schedule(()=>s.snap({...t,context:o,signal:n}),n);e.valid&&await i.schedule(()=>{this.stagedPoint=e.apply(),t!==this._snapPoints&&null!=this._snapPoints&&(this.stagedPoint=s.update({...this._snapPoints,context:o}))},n)})}get stagedPoint(){return this._stagedPoint}set stagedPoint(t){this._stagedPoint=this.constrainResult(t)}initialize(){const t="3d"===this.view.type?this.view?.resourceController?.scheduler:null;this._frameTask=null!=t?t.registerTask(l.SNAPPING):a}destroy(){this._abortController=o(this._abortController),this._frameTask=n(this._frameTask)}update(t,s,o){this._snapPoints=t;const{point:n,scenePoint:i}=t,e=s.update({point:n,scenePoint:i,context:o});return this.stagedPoint=e,e}async snap(t,s,o){const{point:n,scenePoint:i}=t;return this.stagedPoint=s.update({point:n,scenePoint:i,context:o}),this._snapPoints=t,null==this._abortController&&(this._abortController=new AbortController),this._snap(t,s,o,this._abortController.signal)}async snapAgainNearPreviousMapPoint(t,s){null!=this._snapPoints&&await this.snap(this._snapPoints,t,s)}abort(){this._abortController=o(this._abortController),this._snapPoints=null}};t([e({constructOnly:!0})],p.prototype,"view",void 0),t([e()],p.prototype,"stagedPoint",null),t([e()],p.prototype,"constrainResult",void 0),t([e()],p.prototype,"_stagedPoint",void 0),p=t([r("esri.views.interactive.snapping.SnappingOperation")],p);export{p as SnappingOperation};
