/*
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","../../../core/maybe","../../../core/promiseUtils","../../../layers/graphics/dehydratedFeatureComparison","../dragEventPipeline","./SnappingContext","../../support/Scheduler"],(function(e,n,t,o,i,r,a,s){"use strict";let p=function(){function e(){this.next=new r.EventPipeline}return e.prototype.createSnapDragEventPipelineStep=function({predicate:e=(()=>!0),cancel:p,snappingManager:l,snappingContext:d,updatingHandles:c}){var u=this;if(t.isNone(l))return e=>e;let m=null,x=null;const y=()=>{m=t.abortMaybe(m),l.doneSnapping(),t.isSome(x)&&x.frameTask.remove(),x=null};p.next((e=>(y(),e))),this.next=new r.EventPipeline;const g=o.debounce(function(){var e=n._asyncToGenerator((function*({frameTask:e,point:n,context:t,event:o,dx:r,dy:a},s){const p=yield e.schedule((()=>l.snap(n,t,s)),s);if(p.valid){let d=yield e.schedule((()=>p.apply()),s);n!==f&&(d=l.update(f,t)),i.pointEquals(d,v)||(o.mapEnd.x=d.x+r,o.mapEnd.y=d.y+a,u.next.execute(o))}}));return function(n,t){return e.apply(this,arguments)}}());let f,v;return n=>{if(!e(n))return n;if("start"===n.action){const e="3d"===l.view.type?l.view.resourceController.scheduler.registerTask(s.TaskPriority.SNAPPING):s.ImmediateTask;x={context:new a.SnappingContext({editGeometryOperations:d.editGeometryOperations,elevationInfo:d.elevationInfo,pointer:d.pointer,vertexHandle:t.isSome(n.info)?n.info.handle:null,excludeFeature:d.excludeFeature,visualizer:d.visualizer}),originalPos:t.isSome(n.snapOrigin)?d.coordinateHelper.vectorToDehydratedPoint(n.snapOrigin):n.mapStart,frameTask:e}}if(t.isSome(x)){const e=x.context.coordinateHelper.vectorToDehydratedPoint(x.context.coordinateHelper.arrayToVector([x.originalPos.x,x.originalPos.y,x.originalPos.z]));e.x+=n.mapEnd.x-n.mapStart.x,e.y+=n.mapEnd.y-n.mapStart.y;const i=n.mapStart.x-x.originalPos.x,r=n.mapStart.y-x.originalPos.y,a={...n,action:"update"},s=x.context,p=l.update(e,x.context);if(v=p,n.mapEnd.x=p.x+i,n.mapEnd.y=p.y+r,f=e,"end"!==n.action){const n=x.frameTask;t.isSome(m)||(m=new AbortController),c.addPromise(o.ignoreAbortErrors(g({frameTask:n,event:a,context:s,point:e,dx:i,dy:r},m.signal)))}}return"end"===n.action&&y(),n}},e}();e.SnappingPipeline=p,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
