/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{makeHandle as t}from"../../../../../../core/handleUtils.js";import{zeroMeters as e}from"../../../../../../core/quantity.js";import{rotateZ as o}from"../../../../../../core/libs/gl-matrix-2/math/mat4.js";import{e as i}from"../../../../../../chunks/vec32.js";import{clone as n}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{sm4d as a,sv3d as s}from"../../../../../../geometry/support/vectorStacks.js";import{ShiftManipulator as r}from"../../../../analysis/Slice/ShiftManipulator.js";import{IsShiftEdgeOnScreenFlag as l}from"../../../../analysis/Slice/sliceToolUtils.js";import{screenToZConstrained as p}from"../../dragEventPipeline3D.js";import{MoveXYObjectManipulation as c}from"../../manipulations/MoveXYObjectManipulation.js";import{createManipulatorDragEventPipeline as u,addMapDelta as m,addScreenDelta as h}from"../../../../../interactive/dragEventPipeline.js";import{TranslateTooltipInfo as d}from"../../../../../interactive/tooltip/infos/TranslateTooltipInfo.js";import{TranslateZTooltipInfo as v}from"../../../../../interactive/tooltip/infos/TranslateZTooltipInfo.js";import{verticalSignedDistance as f}from"../../../../../support/euclideanLengthMeasurementUtils.js";class _{get _object(){return this._tool.object}get _operations(){return this._object.operations}constructor(t,e,o){this._tool=t,this._bounds=e,this._automaticLengthMeasurementUtils=o,this._moveXYTooltipInfo=null,this._moveZTooltipInfo=null;const i=this._tool,n=i.view;this.moveXYObjectManipulation=new c({view:n,tool:i,object:this._object}),i.addHandles(this._createMoveXYObjectDragPipeline()),this.moveZManipulator=new r(n,0),this.moveZManipulator.state|=l,i.manipulators.add(this.moveZManipulator),i.addHandles(this._createMoveZDragPipeline()),i.addHandles(i.events.on("translate-stop",()=>{this._moveXYTooltipInfo=null,this._moveZTooltipInfo=null}))}destroy(){this.moveXYObjectManipulation.destroy(),this._tool.manipulators.remove(this.moveZManipulator),this.moveZManipulator.destroy()}forEachManipulator(t){this.moveXYObjectManipulation.forEachManipulator(t),t(this.moveZManipulator,0)}updateManipulators(t,e){const n=this.moveZManipulator,r=o(a.get(),t,Math.PI);r[12]=0,r[13]=0,r[14]=0,n.modelTransform=r,n.renderLocation=i(s.get(),e.origin,e.basis1)}getUpdatedTooltipInfo(){return this.moveXYObjectManipulation.grabbing||this.moveXYObjectManipulation.dragging?this._computeMoveXYTooltipInfo():this.moveZManipulator.focused?this._computeMoveZTooltipInfo():null}_computeMoveXYTooltipInfo(){const t=this._tool,o=this._moveXYTooltipInfo??=new d({sketchOptions:t.sketchOptions});if(this.moveXYObjectManipulation.dragging){const e=this._bounds,i=e.mapBoundsStart.origin,n=e.mapBounds.origin,{renderSpatialReference:a}=t.view;if(!a)return null;const s=this._automaticLengthMeasurementUtils.autoDistance2D(i,n,a);if(null==s)return null;o.distance=s}else o.distance=e;return o}_computeMoveZTooltipInfo(){const t=this._tool,o=this._moveZTooltipInfo??=new v({sketchOptions:t.sketchOptions});if(this.moveZManipulator.dragging){const e=this._bounds,i=e.mapBoundsStart.origin,n=e.mapBounds.origin,{renderSpatialReference:a}=t.view;if(!a)return null;const s=f(i,n,a);if(null==s)return null;o.distance=s}else o.distance=e;return o}_createMoveXYObjectDragPipeline(){return this.moveXYObjectManipulation.createDragPipeline((t,e,o)=>this._buildMoveDragPipeline(e,o))}_createMoveZDragPipeline(){if(!this._operations)return t();const e=this._operations.data.spatialReference;return u(this.moveZManipulator,(t,o,i)=>{const a=n(t.renderLocation),s=o.next(p(this._tool.view,a,e)).next(h());this._buildMoveDragPipeline(s,i)})}_buildMoveDragPipeline(t,e){const{_tool:o,_object:i}=this;t.next(t=>("start"===t.action&&(o.inputState={type:"move"},this._bounds.backupMapBounds(),o.events.emit("translate-start",{object:i,dxScreen:t.screenDeltaX,dyScreen:t.screenDeltaY})),t)).next(m()).next(this._updateGeometry()).next(t=>{const e={object:i,dxScreen:t.screenDeltaX,dyScreen:t.screenDeltaY};switch(t.action){case"start":case"update":(t.mapEnd.x-t.mapStart.x||t.mapEnd.y-t.mapStart.y||(t.mapEnd.z??0)-(t.mapStart.z??0))&&o.events.emit("translate",e);break;case"end":o.inputState=null,o.events.emit("translate-stop",e)}return t}),e.next(()=>{null!=o.inputState&&o.events.emit("translate-stop",{object:i,dxScreen:0,dyScreen:0}),o.cancelDrag()})}_updateGeometry(){const t=this._tool;return e=>{if(null==t.inputState||"move"!==t.inputState.type)return e;const o="start"===e.action?0:1;if(this._operations){const t=this._operations.move(e.mapDeltaX,e.mapDeltaY,e.mapDeltaZ,o);this._bounds.updateMapBoundsFromOperation(t)}return e}}}export{_ as ExtentMove};
