/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{debounce as r,ignoreAbortErrors as s}from"../../../../core/promiseUtils.js";import{createLength as o}from"../../../../core/quantity.js";import{watch as i,syncAndInitial as n}from"../../../../core/reactiveUtils.js";import{property as a,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as u}from"../../../../core/support/UpdatingHandles.js";import{isSupported as p,geodesicDensify as c,geodesicLengths as m}from"../../../../geometry/geodesicUtils.js";import{l as d,e as f}from"../../../../chunks/geodeticDensifyOperator.js";import{l as g,e as h}from"../../../../chunks/geodeticLengthOperator.js";import{e as y}from"../../../../chunks/lengthOperator.js";import{load as j,execute as _}from"../../../../geometry/operators/projectOperator.js";import{e as v}from"../../../../chunks/simplifyOperator.js";const w=o(1e5,"meters");async function H(e,t){if(!e?.paths.length||!e.paths[0].length)return null;await j();const r=_(e,t);return r?r.spatialReference.isGeographic?p(r.spatialReference)?D(r):R(r):r.spatialReference.isWebMercator?R(r):O(r):null}async function R(e){await Promise.all([d(),g()]);const t=v(e);if(!t)return null;const r=f(t,w.value,{unit:w.unit});if(!r)return null;const s=h(t,{unit:"meters"});return{display:{outline:r},mode:"geodesic",length:o(s,"meters")}}function D(e){const t=v(e);if(!t)return null;const r=c(t,w.value),s=m([t],"meters")[0];return{display:{outline:r},mode:"geodesic",length:o(s,"meters")}}function O(e){const t=v(e);if(!t)return null;const r=y(t,{unit:"meters"});return{display:{outline:t},mode:"euclidean",length:o(r,"meters")}}let b=class extends t{constructor(e){super(e),this._result=null,this._updatingHandles=new u,this._debouncedGetResult=r(async e=>{this._result=await H(e,this.view.spatialReference)})}initialize(){this.addHandles(i(()=>this.measurementViewData.analysis.geometry,e=>{this._updatingHandles.addPromise(s(this._debouncedGetResult(e)))},n))}destroy(){this._updatingHandles.destroy()}get result(){return this._result}get updating(){return this._updatingHandles.updating}};e([a()],b.prototype,"_result",void 0),e([a()],b.prototype,"measurementViewData",void 0),e([a()],b.prototype,"result",null),e([a()],b.prototype,"updating",null),e([a()],b.prototype,"view",void 0),b=e([l("esri.views.2d.analysis.DistanceMeasurement.DistanceMeasurementController")],b);export{b as DistanceMeasurementController};
