/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../../../core/Accessor.js";import{destroyHandle as s}from"../../../../core/handleUtils.js";import o from"../../../../core/Logger.js";import{mapCollection as r}from"../../../../core/mapCollectionUtils.js";import{debounce as i}from"../../../../core/promiseUtils.js";import{watch as n,syncAndInitial as a}from"../../../../core/reactiveUtils.js";import{convertUnit as m}from"../../../../core/units.js";import{property as p,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as d}from"../../../../core/support/UpdatingHandles.js";import{getDefaultUnitForView as c}from"../../../../support/getDefaultUnitForView.js";import{isGeodesicDimension as u,computeGeometryFromDimension as h,computationToGeometryDependencies as y,computeLength as g}from"./lengthDimensionUtils.js";import{GeometryWorkerHandle as f}from"../../../support/GeometryWorkerHandle.js";import{geodeticDistanceThresholdMeters as w}from"../../../support/measurementWorkerUtils.js";let _=class extends e{constructor(t){super(t),this._measurementWorker=new f({preloadGeodetic:!0}),this._updatingHandles=new d}initialize(){const t=r(()=>this.analysisViewData.computations,({computation:t})=>this._watchComputation(t));this.addHandles(s(t))}destroy(){this._measurementWorker.destroy(),this._updatingHandles.destroy()}get analysis(){return this.analysisViewData.analysis}get _defaultUnit(){return c(this.view)}get updating(){return this._updatingHandles.updating}_watchComputation(t){const e=i(this._computeLengthAsync.bind(this));return n(()=>y(t),s=>{const{measureType:r}=s;if(u(s)&&"direct"!==r){const e=Math.round(m(w,"meters","kilometers"));return o.getLogger(this).warnOnce(`A ${r} dimension in the analysis (id: '${this.analysis.id}') will not display, because only direct dimensions can measure lengths greater than ${e} km. Update the measureType of the affected dimension to "direct" to display it.`),void(t.geometry=null)}const i=h(s,this.view.renderCoordsHelper,t.geometry);this._updatingHandles.consumePromise(e(t,i,r))},a)}async _computeLengthAsync(t,e,s){t.geometry=e,t.result.length=await g(e,s,this._defaultUnit,this._measurementWorker)}};t([p({constructOnly:!0})],_.prototype,"analysisViewData",void 0),t([p({constructOnly:!0})],_.prototype,"view",void 0),t([p()],_.prototype,"analysis",null),t([p()],_.prototype,"_defaultUnit",null),_=t([l("esri.views.3d.analysis.Dimension.DimensionController")],_);export{_ as DimensionController};
