/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{deprecatedModule as t}from"../core/deprecate.js";import i from"../core/Logger.js";import{ignoreAbortErrors as s}from"../core/promiseUtils.js";import{watch as r}from"../core/reactiveUtils.js";import{property as n,subclass as a}from"../core/accessorSupport/decorators.js";import o from"./Widget.js";import l from"./Measurement/MeasurementViewModel.js";import{messageBundle as d,tsx as u}from"./support/widget.js";const c={base:"esri-measurement"};function g(e){return"esri.widgets.AreaMeasurement2D"===e?.declaredClass||"esri.widgets.AreaMeasurement3D"===e?.declaredClass}let w=class extends o{constructor(e,s){super(e,s),this._widgets=new Map,this.activeWidget=null,this.messages=null,this.viewModel=new l,t(i.getLogger("esri.widgets.Measurement"),"esri.widgets.Measurement",{replacement:"Measurement components - Area Measurement 2D, Distance Measurement 2D, Area Measurement 3D, Direct Line Measurement 3D",version:"5.0",see:"https://www.esriurl.com/components-transition-plan/",warnOnce:!0})}initialize(){this.activeWidget&&this.viewModel.set("activeViewModel",this.activeWidget.viewModel),this.view&&this.activeTool&&this._getActiveWidget().then(e=>{this._set("activeWidget",e)}),this.addHandles([r(()=>[this.view,this.activeTool],async()=>{this._set("activeWidget",await this._getActiveWidget())}),r(()=>this.activeWidget,(e,t)=>{this.viewModel.set("activeViewModel",e?e.viewModel:null),t&&(t.visible=!1)}),r(()=>[this.areaUnit,this.linearUnit,this.uiStrings],()=>this._updateSubWidgetProperties())])}destroy(){this._destroyWidgets()}get activeTool(){return this.viewModel.activeTool}set activeTool(e){this.viewModel.activeTool=e}get areaUnit(){return this.viewModel.areaUnit}set areaUnit(e){this.viewModel.areaUnit=e}get icon(){return"measure"}set icon(e){this._overrideIfSome("icon",e)}get label(){return this.messages?.widgetLabel??""}set label(e){this._overrideIfSome("label",e)}get linearUnit(){return this.viewModel.linearUnit}set linearUnit(e){this.viewModel.linearUnit=e}get view(){return this.viewModel.view}set view(e){this.viewModel.view=e}render(){const{activeWidget:e}=this,t=e&&!e.destroyed?e.render():null;return u("div",{class:c.base},t)}clear(){this.activeTool=null,this._destroyWidgets()}startMeasurement(){const{activeViewModel:e}=this.viewModel;e&&s(e.start())}async _createWidget(e){const{areaUnit:t,linearUnit:i,view:s}=this;if(!s)return null;switch(e){case"area":{const{type:i}=s;switch(i){case"2d":return new(0,(await import("./AreaMeasurement2D.js")).default)({view:s,unit:t,uiStrings:this._createUIStringsForWidget(e)});case"3d":return new(0,(await import("./AreaMeasurement3D.js")).default)({view:s,unit:t,uiStrings:this._createUIStringsForWidget(e)});default:return null}}case"distance":{const{type:t}=s;if("2d"===t){return new(0,(await import("./DistanceMeasurement2D.js")).default)({view:s,unit:i,uiStrings:this._createUIStringsForWidget(e)})}return null}case"direct-line":{const{type:t}=s;if("3d"===t){return new(0,(await import("./DirectLineMeasurement3D.js")).default)({view:s,unit:i,uiStrings:this._createUIStringsForWidget(e)})}return null}default:return null}}_destroyWidgets(){this._widgets.forEach(e=>e.destroy()),this._widgets.clear()}async _getActiveWidget(){const{activeTool:e,view:t}=this;if(!t||!e)return null;let i=null;if(this._widgets.has(e))i=this._widgets.get(e),i.visible=!0;else{if(i=await this._createWidget(e),!i)return null;await i.viewModel.start(),this._widgets.set(e,i)}return i}_createUIStringsForWidget(e){if(!this.uiStrings)return;const t=e+"-"+this.view?.type;return this.uiStrings[t]}_updateSubWidgetProperties(){this._widgets.forEach((e,t)=>{const{areaUnit:i,linearUnit:s}=this;e.unit=g(e)?i:s,e.uiStrings=this._createUIStringsForWidget(t)})}};e([n()],w.prototype,"activeTool",null),e([n({readOnly:!0})],w.prototype,"activeWidget",void 0),e([n()],w.prototype,"areaUnit",null),e([n()],w.prototype,"icon",null),e([n()],w.prototype,"label",null),e([n()],w.prototype,"linearUnit",null),e([n(),d("esri/widgets/Measurement/t9n/Measurement")],w.prototype,"messages",void 0),e([n()],w.prototype,"uiStrings",void 0),e([n()],w.prototype,"view",null),e([n({type:l})],w.prototype,"viewModel",void 0),w=e([a("esri.widgets.Measurement")],w);const v=w;export{v as default};
