/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{getZForElevationMode as t}from"../../../../../support/elevationInfoUtils.js";import{EventPipeline as n}from"../../../../interactive/dragEventPipeline.js";class e{constructor(){this._view=null,this._elevationInfo=null,this._lastDragEvent=null,this._next=null,this._enabled=!1}get enabled(){return this._enabled}set enabled(t){if(this._enabled!==t&&null!=this._lastDragEvent&&null!=this._next){const n=this._lastDragEvent.mapEnd,e=this._snap(this._lastDragEvent.screenEnd);if(null!=e){const s={action:"update",mapStart:this._lastDragEvent.mapStart,mapEnd:!0===t?e:n,screenStart:this._lastDragEvent.screenEnd,screenEnd:this._lastDragEvent.screenEnd};this._next.execute(s)}}this._enabled=t}_snap(n){const e=null!=this._view?this._view.toMap(n,{exclude:[]}):null;return null!=e&&null!=this._view&&(e.z=t(e,this._view,this._elevationInfo)),e}createDragEventPipelineStep(t,e){this._view=t,this._elevationInfo=e,this._lastDragEvent=null;const s=new n;this._next=s;return[t=>{if(this._lastDragEvent="end"!==t.action?{...t}:null,this._enabled){const n=this._snap(t.screenEnd);return null!=n?{action:t.action,mapStart:t.mapStart,mapEnd:n,screenStart:t.screenStart,screenEnd:t.screenEnd}:null}return{action:t.action,mapStart:t.mapStart,mapEnd:t.mapEnd,screenStart:t.screenStart,screenEnd:t.screenEnd}},s]}}export{e as SnapToScene};
