/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/Handles","../../core/maybe","../../core/reactiveUtils","../../core/unitUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../../geometry/projection","../../properties/defaultUnit","./AreaMeasurement2DTool","../support/InteractiveToolViewModel"],(function(e,t,i,o,r,s,n,a,l,u,c,d,p,h,y){"use strict";const m={handleWidth:8,handleColor:[255,128,0,.5],pathWidth:2,pathColor:[255,128,0,1],fillColor:[255,128,0,.3]};let v=function(t){function n(e){var o;return(o=t.call(this,e)||this).supportedViewType="2d",o.unsupportedErrorMessage="AreaMeasurement2DViewModel is only supported in 2D views.",o._handles=new i,o.geodesicDistanceThreshold=1e5,o.measurement=null,o.measurementLabel=null,o.palette=m,o}e._inheritsLoose(n,t);var a=n.prototype;return a.initialize=function(){this._handles.add([r.watch((()=>{var e;return null==(e=o.unwrap(this.view))?void 0:e.spatialReference}),(()=>this.clear())),r.watch((()=>this.unit),(e=>{o.isSome(this.tool)&&(this.tool.unit=e)}),r.initial),r.watch((()=>this.geodesicDistanceThreshold),(e=>{o.isSome(this.tool)&&(this.tool.geodesicDistanceThreshold=e)}),r.initial),r.watch((()=>this.palette),(e=>{o.isSome(this.tool)&&(this.tool.palette=e)}),r.initial)])},a.destroy=function(){this._handles&&(this._handles.destroy(),this._handles=null)},a.start=function(){var t=e._asyncToGenerator((function*(){const e=this.view;o.isSome(e)&&(yield r.whenOnce((()=>e.ready)),h.isProjectionEngineRequired(e.spatialReference)&&(yield d.load())),this.createTool({interactive:!0})}));function i(){return t.apply(this,arguments)}return i}(),a.clear=function(){this.removeTool()},a.constructTool=function(){return new h.AreaMeasurement2DTool({view:o.unwrap(this.view),visible:this.visible,geodesicDistanceThreshold:this.geodesicDistanceThreshold,palette:this.palette,unit:this.unit})},a._validateUnit=function(e){return this.unitOptions.includes(e)?e:this.unitOptions.includes(this.defaultUnit)?this.defaultUnit:this.unitOptions[0]},a._validateUnits=function(e=[]){const t=e.filter((e=>s.measurementAreaUnits.includes(e)));return 0===t.length?s.measurementAreaUnits.slice():t},e._createClass(n,[{key:"state",get:function(){return this.disabled||o.isNone(this.view)||!h.isSupported(this.view.spatialReference)?"disabled":o.isSome(this.tool)&&this.tool.measurement?this.tool.active?"measuring":"measured":"ready"}},{key:"unit",get:function(){return this._validateUnit(this.defaultUnit)},set:function(e){void 0!==e?this._override("unit",this._validateUnit(e)):this._clearOverride("unit")}},{key:"unitOptions",get:function(){return s.measurementAreaUnits},set:function(e){void 0!==e?this._override("unitOptions",this._validateUnits(e)):this._clearOverride("unitOptions")}}]),n}(y.InteractiveToolViewModel);t.__decorate([n.property(p.defaultUnitPropertyMetadata)],v.prototype,"defaultUnit",void 0),t.__decorate([n.property({type:Number})],v.prototype,"geodesicDistanceThreshold",void 0),t.__decorate([n.property({readOnly:!0,aliasOf:"tool.measurement"})],v.prototype,"measurement",void 0),t.__decorate([n.property({readOnly:!0,aliasOf:"tool.measurementLabel"})],v.prototype,"measurementLabel",void 0),t.__decorate([n.property()],v.prototype,"palette",void 0),t.__decorate([n.property({readOnly:!0})],v.prototype,"state",null),t.__decorate([n.property({type:String})],v.prototype,"unit",null),t.__decorate([n.property({type:[String]})],v.prototype,"unitOptions",null),v=t.__decorate([c.subclass("esri.widgets.AreaMeasurement2D.AreaMeasurement2DViewModel")],v);return v}));
