/*
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{destroyMaybe as i}from"../../core/maybe.js";import{watch as n,initial as s,syncAndInitial as r,whenOnce as a}from"../../core/reactiveUtils.js";import{measurementAreaUnits as o}from"../../core/units.js";import{property as p,subclass as l}from"../../core/accessorSupport/decorators.js";import{defaultUnitPropertyMetadata as u}from"../../properties/defaultUnit.js";import{SnappingManager as m}from"../../views/interactive/snapping/SnappingManager.js";import g from"../../views/interactive/snapping/SnappingOptions.js";import{isSupported as h,loadGeometryOperators as d,AreaMeasurement2DTool as c}from"./AreaMeasurement2DTool.js";import{InteractiveToolViewModelMixin as v}from"../support/InteractiveToolViewModelMixin.js";let w=class extends(v(t)){constructor(e){super(e),this.supportedViewType="2d",this.unsupportedErrorMessage="AreaMeasurement2DViewModel is only supported in 2D views.",this._snappingManager=null,this.snappingOptions=new g}initialize(){this.addHandles([n(()=>this.view?.spatialReference,()=>this.clear()),n(()=>this.unit,e=>{null!=this.tool&&(this.tool.unit=e)},s),n(()=>this.view,e=>{this._snappingManager=i(this._snappingManager),e&&(this._snappingManager=new m({view:e,options:this.snappingOptions}))},r),n(()=>this.snappingOptions,e=>{this._snappingManager&&e&&(this._snappingManager.options=e)})])}destroy(){this._snappingManager=i(this._snappingManager)}get measurement(){return this.tool?.measurement??null}get measurementLabel(){return this.tool?.measurementLabel??null}get state(){return this.disabled||null==this.view||!h(this.view.spatialReference)?"disabled":this.tool?.measurement?this.tool.active?"measuring":"measured":"ready"}get unit(){return this._validateUnit(this.defaultUnit)}set unit(e){this._overrideIfSome("unit",this._validateUnit(e))}get unitOptions(){return o}set unitOptions(e){this._overrideIfSome("unitOptions",this._validateUnits(e))}get view(){return super.view}set view(e){super.view=e}async start(){const{view:e}=this;e&&(await a(()=>e.ready),await d(e.spatialReference)),this.createTool({interactive:!0})}clear(){this.removeTool()}constructTool(){return new c({snappingManager:this._snappingManager,unit:this.unit,view:this.view,visible:this.visible})}_validateUnit(e){const{unitOptions:t,defaultUnit:i}=this;return null!=e&&t.includes(e)?e:t.includes(i)?i:t.length>0?t[0]:i}_validateUnits(e){if(null==e)return[];const t=e.filter(e=>o.includes(e));return 0===t.length?o.slice():t}};e([p()],w.prototype,"_snappingManager",void 0),e([p(u)],w.prototype,"defaultUnit",void 0),e([p({readOnly:!0})],w.prototype,"measurement",null),e([p({readOnly:!0})],w.prototype,"measurementLabel",null),e([p({type:g,nonNullable:!0})],w.prototype,"snappingOptions",void 0),e([p({readOnly:!0})],w.prototype,"state",null),e([p({type:String})],w.prototype,"unit",null),e([p({type:[String]})],w.prototype,"unitOptions",null),w=e([l("esri.widgets.AreaMeasurement2D.AreaMeasurement2DViewModel")],w);const f=w;export{f as default};
