/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import s from"../../../../Graphic.js";import t from"../../../../core/Accessor.js";import{createTask as i}from"../../../../core/asyncUtils.js";import{formatLength as r}from"../../../../core/quantityFormatUtils.js";import{initial as a}from"../../../../core/reactiveUtils.js";import{property as o,subclass as n}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as l}from"../../../../core/support/UpdatingHandles.js";import{onLocaleChange as p}from"../../../../intl/locale.js";import{fetchMessageBundle as m}from"../../../../intl/messages.js";import h from"../../../../layers/GraphicsLayer.js";import{getDistanceMeasurementSymbol as c}from"./utils.js";let d=class extends t{get _messages(){return this._messagesTask?.value}constructor(e){super(e),this._graphicsLayer=new h({listMode:"hide",internal:!0}),this._updatingHandles=new l}initialize(){this.view.map?.add(this._graphicsLayer),this.addHandles(p(()=>this._updateMessageBundle())),this._updatingHandles.add(()=>({accentColor:this.view.effectiveTheme.accentColor,length:this.measurementViewData.result?.length,messages:this._messages,outline:this.measurementViewData.result?.display.outline,textColor:this.view.effectiveTheme.textColor,unit:this.measurementViewData.unit,visible:this.measurementViewData.visible}),({accentColor:e,length:t,messages:i,outline:a,textColor:o,unit:n,visible:l},p)=>{if(this._graphicsLayer.visible=l,!l)return;if(!i||!t||!a)return void this._graphicsLayer.graphics.destroyAll();const m=this._graphicsLayer.graphics.at(0),h=i&&t?r(i,t,n):"";if(m&&e.equals(p?.accentColor)&&o.equals(p?.textColor))return m.setAttribute("lengthText",h),void(m.geometry=a);this._graphicsLayer.graphics.destroyAll(),this._graphicsLayer.add(new s({attributes:{lengthText:h},geometry:a,symbol:c(e,o)}))},a),this._updateMessageBundle()}destroy(){this._graphicsLayer.removeFromParent(),this._graphicsLayer.graphics.destroyAll(),this._graphicsLayer.destroy(),this._updatingHandles.destroy()}get updating(){return!this._graphicsLayer.loaded||!this._messagesTask?.finished||this._updatingHandles.updating}_updateMessageBundle(){return this._messagesTask?.abort(),this._messagesTask=i(()=>m("esri/core/t9n/Units")),this._messagesTask.promise}};e([o()],d.prototype,"_messages",null),e([o()],d.prototype,"_messagesTask",void 0),e([o()],d.prototype,"measurementViewData",void 0),e([o()],d.prototype,"updating",null),e([o()],d.prototype,"view",void 0),d=e([n("esri.views.2d.analysis.DistanceMeasurement.DistanceMeasurementLineVisualization")],d);export{d as DistanceMeasurementLineVisualization};
