/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{handlesGroup as t}from"../../../core/handleUtils.js";import{zeroMeters as e}from"../../../core/quantity.js";import{watch as o,syncAndInitial as n,sync as i}from"../../../core/reactiveUtils.js";import{createScreenPoint as r}from"../../../core/screenUtils.js";import a from"../../../geometry/Point.js";import{isCurvedGeometry as s}from"../../../geometry/support/curves/curveUtils.js";import{connectPasteEvent as c,getXYZDeltasFromTooltipInfo as l}from"../../interactive/tooltip/tooltipCommonUtils.js";import{MovePointTooltipInfo as p}from"../../interactive/tooltip/infos/MovePointTooltipInfo.js";import{SelectedVertexTooltipInfo as m}from"../../interactive/tooltip/infos/SelectedVertexTooltipInfo.js";import{TranslateTooltipInfo as u}from"../../interactive/tooltip/infos/TranslateTooltipInfo.js";import{TranslateVertexTooltipInfo as f}from"../../interactive/tooltip/infos/TranslateVertexTooltipInfo.js";import{elevationFromPoint as y}from"../../support/euclideanLengthMeasurementUtils.js";function v(t){const e={sketchOptions:t,viewType:"2d"};return{movePoint:new p(e),selectedVertex:new m(e),translateGraphic:new u(e),translateVertices:new f(e)}}function g(e,r){function a(){const t=r(),e=t.sketchOptions.tooltips.effectiveEnabled?t.activeTooltipInfo:null;return{...t,activeTooltipInfo:e}}let s=!1;function l(t){s||(s=!0,t(),s=!1)}return t([o(()=>{const t=a();return{context:t,geometry:t.graphic?.geometry,vertexGeometry:t.selectedVertex?.geometry}},({context:t})=>{l(()=>{h(t),e.info=t.activeTooltipInfo})},n),o(()=>{const t=a(),{activeTooltipInfo:e}=t;if(e&&"key"in e)return{context:t,key:e.key}},(t,e)=>{t&&e&&t.key!==e.key&&l(()=>j(t.context))},i),c(e,{onBeforePaste:()=>{s=!0},onAfterPaste:()=>{j(a()),s=!1}})])}function h(t){const e=t.activeTooltipInfo;if(e){switch(e?.type){case"move-point":return d(e,t);case"selected-vertex":return x(e,t)}e.sketchOptions=t.sketchOptions}}function d(t,{graphic:e}){T(t,e,e?.geometry)}function x(t,{graphic:e,selectedVertex:o,automaticAreaMeasurementUtils:n,automaticLengthMeasurementUtils:i}){T(t,e,o?.geometry);const r=e?.geometry;if(!r||!s(r))switch(r?.type){case"polygon":t.geometryType="polygon",t.totalLength.visible=!1,t.area.actual=n.autoArea2D(r);break;case"polyline":t.geometryType="polyline",t.totalLength.actual=i.autoLength2D(r),t.area.visible=!1;break;case"multipoint":t.geometryType="multipoint",t.area.visible=!1,t.totalLength.visible=!1}}function T(t,e,o){e&&"point"===o?.type&&(t.setLocationFromPoint(o),t.elevation.actual=y(o),t.elevation.visible=!!e.geometry?.hasZ,t.elevation.readOnly=!1,t.elevation.showAsZ=!0)}function j(t){function e(e,o){const n=o?.geometry;if(!n||"point"!==n.type)return;const{dx:i,dy:r,dz:s}=l(e,n);if(0===i&&0===r&&0===s)return;const{x:c,y:p,z:m,m:u,spatialReference:f}=n,y=new a({x:c+i,y:p+r,z:null!=m?m+s:void 0,m:u,spatialReference:f});t.updateGeometry(o,y,n,i,r)}const{activeTooltipInfo:o,graphic:n,selectedVertex:i}=t;switch(o?.type){case"move-point":return e(o,n);case"selected-vertex":return e(o,i)}}function k(t,e,o,n){t.clear(),L(t,e,n,o)}function w(t,e,o,n,i){if(t.clear(),o&&s(o))return;const{automaticAreaMeasurementUtils:r,automaticLengthMeasurementUtils:a}=n;"polygon"===o?.type?t.area=r.autoArea2D(o):"polyline"===o?.type&&(t.totalLength=a.autoLength2D(o)),L(t,e,i,n)}function L(t,o,n,{automaticLengthMeasurementUtils:i}){if(!n)return;const{x:a,y:s}=n.origin,c=o.toMap(n),l=o.toMap(r(a,s)),p=i.autoDistanceBetweenPoints2D(l,c);t.distance=null!=p?p:e}export{g as connectTooltip,v as createTooltipInfos,k as updateTranslateTooltipInfo,w as updateTranslateVertexTooltipInfo};
