/*
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 e}from"tslib";import t from"../../../../core/Accessor.js";import{debounce as r,ignoreAbortErrors as s}from"../../../../core/promiseUtils.js";import{createLength as i,createArea as o}from"../../../../core/quantity.js";import{watch as n,syncAndInitial as a}from"../../../../core/reactiveUtils.js";import{property as u,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as m}from"../../../../core/support/UpdatingHandles.js";import{isSupported as p,geodesicDensify as c,geodesicLengths as d,geodesicAreas as f}from"../../../../geometry/geodesicUtils.js";import g from"../../../../geometry/Polyline.js";import{e as h}from"../../../../chunks/areaOperator.js";import{l as y,e as j}from"../../../../chunks/geodeticAreaOperator.js";import{l as v,e as w}from"../../../../chunks/geodeticDensifyOperator.js";import{l as _,e as R}from"../../../../chunks/geodeticLengthOperator.js";import{e as q}from"../../../../chunks/lengthOperator.js";import{load as O,execute as k}from"../../../../geometry/operators/projectOperator.js";import{e as H}from"../../../../chunks/simplifyOperator.js";const b=i(1e5,"meters");async function A(e,t){if(!e?.rings.length||!e.rings[0].length)return null;await O();const r=k(e,t);return r?r.spatialReference.isGeographic?p(r.spatialReference)?D(r):U(r):r.spatialReference.isWebMercator?U(r):G(r):null}async function U(e){await Promise.all([y(),v(),_()]);const t=H(e);if(!t)return null;const r=M(t),s=w(t,b.value,{unit:b.unit});if(!s)return null;const n=w(r,b.value,{unit:b.unit});if(!n)return null;const a=R(t,{unit:"meters"}),u=j(t,{unit:"square-meters"});return{area:o(u,"square-meters"),display:{fill:s,outline:n},mode:"geodesic",perimeter:i(a,"meters")}}function D(e){const t=H(e);if(!t)return null;const r=M(t),s=c(t,b.value),n=c(r,b.value),a=d([t],"meters")[0],u=f([t],"square-meters")[0];return{area:o(u,"square-meters"),display:{fill:s,outline:n},mode:"geodesic",perimeter:i(a,"meters")}}function G(e){const t=H(e);if(!t)return null;const r=M(t),s=q(r,{unit:"meters"}),n=h(t,{unit:"square-meters"});return{area:o(n,"square-meters"),display:{fill:t,outline:r},mode:"euclidean",perimeter:i(s,"meters")}}function M(e){return new g({spatialReference:e.spatialReference,paths:e.rings})}let P=class extends t{constructor(e){super(e),this._result=null,this._updatingHandles=new m,this._debouncedGetResult=r(async e=>{this._result=await A(e,this.view.spatialReference)})}initialize(){this.addHandles(n(()=>this.measurementViewData.analysis.geometry,e=>{this._updatingHandles.addPromise(s(this._debouncedGetResult(e)))},a))}destroy(){this._updatingHandles.destroy()}get result(){return this._result}get updating(){return this._updatingHandles.updating}};e([u()],P.prototype,"_result",void 0),e([u()],P.prototype,"measurementViewData",void 0),e([u()],P.prototype,"result",null),e([u()],P.prototype,"updating",null),e([u()],P.prototype,"view",void 0),P=e([l("esri.views.2d.analysis.AreaMeasurement.AreaMeasurementController")],P);export{P as AreaMeasurementController};
