/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","../core/has","../core/promiseUtils","../core/reactiveUtils","../core/accessorSupport/decorators/aliasOf","../core/arrayUtils","../core/accessorSupport/ensureType","../core/accessorSupport/decorators/property","../core/accessorSupport/decorators/subclass","./Widget","./Measurement/MeasurementViewModel","./support/widgetUtils","./support/decorators/messageBundle","./support/jsxFactory"],(function(e,t,i,r,s,o,n,a,c,l,d,u,g,p,v,w){"use strict";const h=e=>Object.freeze(Object.defineProperty({__proto__:null,default:e},Symbol.toStringTag,{value:"Module"})),_={base:"esri-measurement",widgetIcon:"esri-icon-measure"};function y(e){return e&&("esri.widgets.AreaMeasurement2D"===e.declaredClass||"esri.widgets.AreaMeasurement3D"===e.declaredClass)}let f=function(i){function r(e,t){var r;return(r=i.call(this,e,t)||this)._widgets=new Map,r.activeTool=null,r.activeWidget=null,r.areaUnit=null,r.iconClass=_.widgetIcon,r.label=void 0,r.linearUnit=null,r.messages=null,r.view=null,r.viewModel=new g,r}t._inheritsLoose(r,i);var n=r.prototype;return n.initialize=function(){var e=this;this.activeWidget&&this.viewModel.set("activeViewModel",this.activeWidget.viewModel),this.view&&this.activeTool&&this._getActiveWidget().then((e=>{this._set("activeWidget",e)})),this.own([o.watch((()=>[this.view,this.activeTool]),t._asyncToGenerator((function*(){e._set("activeWidget",yield e._getActiveWidget())}))),o.watch((()=>this.activeWidget),((e,t)=>{this.viewModel.set("activeViewModel",e?e.viewModel:null),t&&(t.visible=!1)})),o.watch((()=>[this.areaUnit,this.linearUnit,this.uiStrings]),(()=>this._updateSubWidgetProperties()))])},n.destroy=function(){this._destroyWidgets()},n.render=function(){const{activeWidget:e}=this,t=e&&!e.destroyed?e.render():null;return w.tsx("div",{class:_.base},t)},n.clear=function(){this.activeTool=null,this._destroyWidgets()},n.startMeasurement=function(){const{activeViewModel:e}=this.viewModel;e&&s.ignoreAbortErrors(e.start())},n._createWidget=function(){var i=t._asyncToGenerator((function*(t){const{areaUnit:i,linearUnit:r,view:s}=this;switch(t){case"area":{const{type:r}=s;switch(r){case"2d":return new(0,(yield new Promise(((t,i)=>e(["./AreaMeasurement2D"],(e=>t(h(e))),i)))).default)({view:s,unit:i,uiStrings:this._createUIStringsForWidget(t)});case"3d":return new(0,(yield new Promise(((t,i)=>e(["./AreaMeasurement3D"],(e=>t(h(e))),i)))).default)({view:s,unit:i,uiStrings:this._createUIStringsForWidget(t)});default:return null}}case"distance":return new(0,(yield new Promise(((t,i)=>e(["./DistanceMeasurement2D"],(e=>t(h(e))),i)))).default)({view:s,unit:r,uiStrings:this._createUIStringsForWidget(t)});case"direct-line":return new(0,(yield new Promise(((t,i)=>e(["./DirectLineMeasurement3D"],(e=>t(h(e))),i)))).default)({view:s,unit:r,uiStrings:this._createUIStringsForWidget(t)});default:return null}}));function r(e){return i.apply(this,arguments)}return r}(),n._destroyWidgets=function(){this._widgets.forEach((e=>e.destroy())),this._widgets.clear()},n._getActiveWidget=function(){var e=t._asyncToGenerator((function*(){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=yield this._createWidget(e),!i)return null;yield i.viewModel.start(),this._widgets.set(e,i)}return i}));function i(){return e.apply(this,arguments)}return i}(),n._createUIStringsForWidget=function(e){if(!this.uiStrings)return null;const t=e+"-"+this.view.type;return this.uiStrings[t]},n._updateSubWidgetProperties=function(){this._widgets.forEach(((e,t)=>{const{areaUnit:i,linearUnit:r}=this;e.unit=y(e)?i:r,e.uiStrings=this._createUIStringsForWidget(t)}))},r}(u);i.__decorate([n.aliasOf("viewModel.activeTool")],f.prototype,"activeTool",void 0),i.__decorate([l.property({readOnly:!0})],f.prototype,"activeWidget",void 0),i.__decorate([n.aliasOf("viewModel.areaUnit")],f.prototype,"areaUnit",void 0),i.__decorate([l.property()],f.prototype,"iconClass",void 0),i.__decorate([l.property({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],f.prototype,"label",void 0),i.__decorate([n.aliasOf("viewModel.linearUnit")],f.prototype,"linearUnit",void 0),i.__decorate([l.property(),v.messageBundle("esri/widgets/Measurement/t9n/Measurement")],f.prototype,"messages",void 0),i.__decorate([l.property()],f.prototype,"uiStrings",void 0),i.__decorate([n.aliasOf("viewModel.view")],f.prototype,"view",void 0),i.__decorate([l.property({type:g})],f.prototype,"viewModel",void 0),f=i.__decorate([d.subclass("esri.widgets.Measurement")],f);return f}));
