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