/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as t}from"tslib";import o from"../../../../core/Accessor.js";import{createTask as e}from"../../../../core/asyncUtils.js";import{makeHandle as i}from"../../../../core/handleUtils.js";import{destroyMaybe as s}from"../../../../core/maybe.js";import{throwIfAborted as n}from"../../../../core/promiseUtils.js";import{watch as r,when as a,syncAndInitial as l}from"../../../../core/reactiveUtils.js";import{property as p}from"../../../../core/accessorSupport/decorators.js";import{subclass as c}from"../../../../core/accessorSupport/decorators/subclass.js";import{UpdatingHandles as m}from"../../../../core/support/UpdatingHandles.js";import{absoluteHeightElevationInfo as u}from"../../../../support/elevationInfoUtils.js";import{getConstraintContext as d}from"../../../interactive/sketch/constraintUtils.js";import{makeTooltip as h}from"../../../interactive/tooltip/tooltipCommonUtils.js";import{DynamicTooltipInfo as f}from"../../../interactive/tooltip/infos/DynamicTooltipInfo.js";import{loadAutomaticAreaMeasurementUtils as g}from"../../../support/automaticAreaMeasurementUtils.js";import{loadAutomaticLengthMeasurementUtils as _}from"../../../support/automaticLengthMeasurementUtils.js";let y=class extends o{constructor(t){super(t),this.constraintsEnabled=!0,this._updatingHandles=new m,this._measurementUtilsLoadTask=null}initialize(){this.addHandles([r(()=>!!this.context?.sketchOptions?.tooltips.enabled,t=>{const{context:o}=this;t&&o?.view&&o.sketchOptions?(this._tooltipInfo??=new f({sketchOptions:o.sketchOptions,getAllFields:this.getAllFields,viewType:o.view.type}),this._tooltip??=h(()=>({view:o.view,options:o.sketchOptions.tooltips,info:this.tooltipInfo}))):(this._tooltip=s(this._tooltip),this._tooltipInfo=s(this._tooltipInfo))},l),a(()=>this._needsMeasurement,()=>{const t=e(async t=>{const[o,e]=await Promise.all([g(),_()]);n(t),this._automaticAreaMeasurementUtils=o,this._automaticLengthMeasurementUtils=e});this.addHandles(i(()=>t.abort())),this._updatingHandles.addPromise(t.promise)},{once:!0,initial:!0})])}destroy(){this._measurementUtilsLoadTask?.abort(),this._tooltip=s(this._tooltip),this._tooltipInfo=s(this._tooltipInfo)}set getAllFields(t){this._set("getAllFields",t),this.tooltipInfo&&(this.tooltipInfo.getAllFields=t)}get context(){return this.getDependencies?.()}get updating(){return this._updatingHandles.updating}get tooltip(){return this._tooltip}get tooltipInfo(){return this._tooltipInfo}get automaticLengthMeasurementUtils(){return this._automaticLengthMeasurementUtils}get automaticAreaMeasurementUtils(){return this._automaticAreaMeasurementUtils}get constraints(){const{tooltipInfo:t,context:o}=this,{view:e,editGeometryOperations:i,elevationInfo:s,sketchOptions:n}=o??{},r=this.getLastScreenPosition?.();if(!(r&&e&&t&&i&&n))return null;const{coordinateHelper:a,spatialReference:l}=i.data,p=e.toMap(r);if(!p)return null;const c=d(p,e,l,s??u,a.hasZ(),n.values.effectiveDirectionMode),m=t.knownConstraintFields,h={context:c};for(const u of m)switch(u.name){case"direction":case"distance":case"elevation":h[u.name]=u.committed;break;case"x":h[u.name]=U(u.committed),h.longitude=v(u.committed);break;case"y":h[u.name]=U(u.committed),h.latitude=v(u.committed)}return h}get _needsMeasurement(){return!!this.context?.sketchOptions.tooltips.enabled}};function v(t){return null!=t&&"unit"in t&&"rotationType"in t?t:null}function U(t){return null==t||"rotationType"in t?null:t}t([p()],y.prototype,"getDependencies",void 0),t([p()],y.prototype,"getLastScreenPosition",void 0),t([p()],y.prototype,"getAllFields",null),t([p()],y.prototype,"context",null),t([p()],y.prototype,"updating",null),t([p()],y.prototype,"tooltip",null),t([p()],y.prototype,"tooltipInfo",null),t([p()],y.prototype,"automaticLengthMeasurementUtils",null),t([p()],y.prototype,"automaticAreaMeasurementUtils",null),t([p()],y.prototype,"constraintsEnabled",void 0),t([p()],y.prototype,"constraints",null),t([p()],y.prototype,"_updatingHandles",void 0),t([p()],y.prototype,"_tooltip",void 0),t([p()],y.prototype,"_tooltipInfo",void 0),t([p()],y.prototype,"_automaticLengthMeasurementUtils",void 0),t([p()],y.prototype,"_automaticAreaMeasurementUtils",void 0),t([p()],y.prototype,"_needsMeasurement",null),y=t([c("esri.views.draw.support.managers.DrawTooltipManager")],y);export{y as DrawTooltipManager};
