/*
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","./DistanceMeasurement2DTool","../support/InteractiveToolViewModel"],(function(e,t,i,o,s,r,n,a,l,u,c,d,p,h,y){"use strict";const v={handleWidth:8,handleColor:[255,128,0,.5],pathWidth:5,pathPrimaryColor:[255,128,0,255],pathSecondaryColor:[255,255,255,255]};let m=function(t){function n(e){var o;return(o=t.call(this,e)||this).supportedViewType="2d",o.unsupportedErrorMessage="DistanceMeasurement2DViewModel is only supported in 2D views.",o._handles=new i,o.geodesicDistanceThreshold=1e5,o.measurement=null,o.measurementLabel=null,o.palette=v,o}e._inheritsLoose(n,t);var a=n.prototype;return a.initialize=function(){this._handles.add([s.watch((()=>{var e;return null==(e=o.unwrap(this.view))?void 0:e.spatialReference}),(()=>this.clear())),s.watch((()=>this.unit),(e=>{o.isSome(this.tool)&&(this.tool.unit=e)}),s.initial),s.watch((()=>this.geodesicDistanceThreshold),(e=>{o.isSome(this.tool)&&(this.tool.geodesicDistanceThreshold=e)}),s.initial),s.watch((()=>this.palette),(e=>{o.isSome(this.tool)&&(this.tool.palette=e)}),s.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 s.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.DistanceMeasurement2DTool({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=>r.measurementLengthUnits.includes(e)));return 0===t.length?r.measurementLengthUnits.slice():t},e._createClass(n,[{key:"state",get:function(){var e;return this.disabled||o.isNone(this.view)||!h.isSupported(null==(e=this.view)?void 0:e.spatialReference)?"disabled":o.isSome(this.tool)&&this.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 r.measurementLengthUnits},set:function(e){void 0!==e?this._override("unitOptions",this._validateUnits(e)):this._clearOverride("unitOptions")}}]),n}(y.InteractiveToolViewModel);t.__decorate([n.property(p.defaultUnitPropertyMetadata)],m.prototype,"defaultUnit",void 0),t.__decorate([n.property({type:Number})],m.prototype,"geodesicDistanceThreshold",void 0),t.__decorate([n.property({readOnly:!0,aliasOf:"tool.measurement"})],m.prototype,"measurement",void 0),t.__decorate([n.property({readOnly:!0,aliasOf:"tool.measurementLabel"})],m.prototype,"measurementLabel",void 0),t.__decorate([n.property()],m.prototype,"palette",void 0),t.__decorate([n.property({readOnly:!0})],m.prototype,"state",null),t.__decorate([n.property({type:String})],m.prototype,"unit",null),t.__decorate([n.property({type:[String]})],m.prototype,"unitOptions",null),m=t.__decorate([c.subclass("esri.widgets.DistanceMeasurement2D.DistanceMeasurement2DViewModel")],m);return m}));
