/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{handlesGroup as t}from"../../../../core/handleUtils.js";import{createAngle as o,createLength as e}from"../../../../core/quantity.js";import{watch as i,syncAndInitial as n,sync as a}from"../../../../core/reactiveUtils.js";import{manipulatedObjectGeometry as r}from"./manipulatedObjectUtils.js";import{connectPasteEvent as s,updateMeshTransformFromTooltipInfo as c,getXYZDeltasFromTooltipInfo as l,updateTooltipInfoFromMeshTransform as u}from"../../../interactive/tooltip/tooltipCommonUtils.js";import{elevationFromPoint as p}from"../../../support/euclideanLengthMeasurementUtils.js";function f(o,e,c){function l(){const t=c(),o=t.sketchOptions.tooltips.effectiveEnabled?t.activeTooltipInfo:null;return{...t,activeTooltipInfo:o}}let u=!1;function p(t){u||(u=!0,t(),u=!1)}function f({activeTooltipInfo:t,sketchOptions:i,scaleRotateTransform:n}){p(()=>{t&&(t.sketchOptions=i,d(t,e),y(t,n)),o.info=t})}return t([i(l,f,n),i(()=>{const t=l(),{activeTooltipInfo:o}=t;if(o)return{context:t,activeTooltipInfo:o,key:o.key,geometry:r(e)}},(t,o)=>{t&&o&&o.key!==t.key&&p(()=>m(e,t.context))},a),e.on("committed",()=>{queueMicrotask(()=>f(l()))}),s(o,{onBeforePaste:()=>{u=!0},onAfterPaste:()=>{m(e,l()),u=!1}})])}function m(t,{activeTooltipInfo:o,callbacks:e}){if(!o)return;e.onBeforeUpdate();const i=r(t);switch(i?.type){case"mesh":v(o,i.origin,t,e),"orientation"in o&&"scale"in o&&c(o,i,e);break;case"point":v(o,i,t,e)}}function v(t,o,e,i){const{dx:n,dy:a,dz:r}=l(t,o);0===n&&0===a&&0===r||(i.onMoveStart(),e.operations?.move(n,a,r,0),i.onMove(n,a,r),i.onMoveStop())}function d(t,o){const e=r(o),i=e?.type;if(!t||!e||"mesh"!==i&&"point"!==i)return;const n="mesh"===i,a=n?e.origin:e;t.setLocationFromPoint(a),h(t,a,o),"transform-mesh"===t.type&&n&&u(t,e),t.clearInputValues()}function h(t,o,e){t.elevation.actual=p(o),t.elevation.visible=!!e.operations?.data.coordinateHelper.hasZ(),t.elevation.readOnly=!1,t.elevation.showAsZ=!0}function y(t,i){if("transform-point"!==t?.type)return;if(!i)return t.orientation.actual=void 0,t.size.actual=void 0,t.orientation.visible=!1,void(t.size.visible=!1);const n=i.mode,{size:a,orientationClockwise:r}=i.adapter,{visualVariables:s}=t.sketchOptions.tooltips,c=s?.rotation,l=null!=r&&(null==n||"rotate"===n),u="geographic";t.orientation.actual=l?o(r,"radians",u):void 0,t.orientation.precision=k(c?.valueType),t.orientation.visible=l;const p=s?.size,f=null!=a&&(null==n||"scale"===n);t.size.actual=f?e(a,p?.unit??"meters"):void 0,t.size.precision=k(p?.valueType),t.size.visible=f}function k(t){switch(t){case"integer":case"long":return 0;default:return null}}export{f as connectTooltipToManipulatedObject,h as updateElevationFromPoint,d as updateTooltipInfoFromManipulatedObject,v as updateXYZFromTooltipInfo};
