/*
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","../../analysis/AreaMeasurementAnalysis","../../core/maybe","../../core/unitUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../../properties/defaultUnit","../../views/3d/interactive/measurementTools/areaMeasurement3D/AreaMeasurement3DTool","../support/InteractiveAnalysisViewModel"],(function(e,t,i,s,n,r,a,o,l,u,c,p,d){"use strict";let y=function(t){function r(e){var i;return(i=t.call(this,e)||this).analysis=null,i.supportedViewType="3d",i.unsupportedErrorMessage="AreaMeasurement3DViewModel is only supported in 3D views.",i._userUnitOptions=null,i._userUnit=null,i}e._inheritsLoose(r,t);var a=r.prototype;return a.initialize=function(){this.analysis.unit=this.unit},a.constructAnalysis=function(){return new i},a.constructTool=function(){return new p({view:s.unwrap(this.view),analysis:this.analysis,analysisViewData:s.unwrap(this.analysisView),visible:this.visible})},a._findSelectableUnit=function(e,t){const{unitOptions:i}=this;return i.includes(e)?e:s.isSome(t)?this._findSelectableUnit(t):i[0]},a._filteredOrAllUnits=function(e){if(s.isNone(e))return n.measurementAreaUnits.slice();const t=e.filter((e=>n.measurementAreaUnits.includes(e)));return 0===t.length?n.measurementAreaUnits.slice():t},e._createClass(r,[{key:"state",get:function(){return this.disabled||!this.ready?"disabled":s.isNone(this.tool)?"ready":this.tool.state}},{key:"measurement",get:function(){if(s.isNone(this.tool)||this.disabled||this.tool.destroyed)return null;const{analysisView:e}=this;if(s.isNone(e))return null;const t=e.analysisVisualization,i=t.viewData,n=i.measurementData,r=e.validMeasurement,a="euclidean"===i.mode,o=0===(a?n.intersectingSegments:n.geodesicIntersectingSegments).size,l=o?r?"available":"unavailable":"invalid";return{mode:a?"euclidean":"geodesic",area:{text:o&&r?t.areaLabel:null,state:l},perimeterLength:{text:o&&r?t.perimeterLengthLabel:null,state:l}}}},{key:"unitOptions",get:function(){return this._filteredOrAllUnits(this._userUnitOptions)},set:function(e){this._userUnitOptions=e,this._set("unitOptions",this._filteredOrAllUnits(this._userUnitOptions))}},{key:"unit",get:function(){return s.isSome(this._userUnit)?(this._userUnit=this._findSelectableUnit(this._userUnit,this.defaultUnit),this._userUnit):this._findSelectableUnit(this.defaultUnit)},set:function(e){this._userUnit=e?this._findSelectableUnit(e,this._userUnit):null,this.analysis.unit=this._userUnit}}]),r}(d.InteractiveAnalysisViewModel);t.__decorate([r.property({type:i})],y.prototype,"analysis",void 0),t.__decorate([r.property({readOnly:!0})],y.prototype,"state",null),t.__decorate([r.property({readOnly:!0})],y.prototype,"measurement",null),t.__decorate([r.property()],y.prototype,"unitOptions",null),t.__decorate([r.property()],y.prototype,"unit",null),t.__decorate([r.property(c.defaultUnitPropertyMetadata)],y.prototype,"defaultUnit",void 0),t.__decorate([r.property()],y.prototype,"_userUnit",void 0),y=t.__decorate([u.subclass("esri.widgets.AreaMeasurement3D.AreaMeasurement3DViewModel")],y);return y}));
