/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import s from"../../../../Graphic.js";import t from"../../../../core/Accessor.js";import{createTask as r}from"../../../../core/asyncUtils.js";import{formatArea as i}from"../../../../core/quantityFormatUtils.js";import{initial as a}from"../../../../core/reactiveUtils.js";import{property as o,subclass as l}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as n}from"../../../../core/support/UpdatingHandles.js";import{onLocaleChange as m}from"../../../../intl/locale.js";import{fetchMessageBundle as p}from"../../../../intl/messages.js";import h from"../../../../layers/GraphicsLayer.js";import{getAreaMeasurementFillSymbol as u,getAreaMeasurementOutlineSymbol as c,getAreaMeasurementTextSymbol as d}from"./utils.js";let g=class extends t{get _messages(){return this._messagesTask?.value}constructor(e){super(e),this._graphicsLayer=new h({listMode:"hide",internal:!0}),this._updatingHandles=new n}initialize(){this.view.map?.add(this._graphicsLayer),this.addHandles(m(()=>this._updateMessageBundle())),this._updatingHandles.add(()=>({accentColor:this.view.effectiveTheme.accentColor,area:this.measurementViewData.result?.area,fill:this.measurementViewData.result?.display.fill,messages:this._messages,outline:this.measurementViewData.result?.display.outline,textColor:this.view.effectiveTheme.textColor,unit:this.measurementViewData.unit,visible:this.measurementViewData.visible}),({accentColor:e,area:t,fill:r,messages:a,outline:o,textColor:l,unit:n,visible:m},p)=>{if(this._graphicsLayer.visible=m,!m)return;if(!(t&&r&&a&&o))return void this._graphicsLayer.graphics.destroyAll();const h=a&&t?i(a,t,n):null;if(3===this._graphicsLayer.graphics.length&&e.equals(p?.accentColor)&&l.equals(p?.textColor)){const[e,s,t]=this._graphicsLayer.graphics.toArray();return e.geometry=r,s.geometry=o,t.setAttribute("areaText",h),void(t.geometry=r)}this._graphicsLayer.graphics.destroyAll(),this._graphicsLayer.addMany([new s({geometry:r,symbol:u(e)}),new s({geometry:o,symbol:c(e)}),new s({attributes:{areaText:h},geometry:r,symbol:d(l)})])},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=r(()=>p("esri/core/t9n/Units")),this._messagesTask.promise}};e([o()],g.prototype,"_messages",null),e([o()],g.prototype,"_messagesTask",void 0),e([o()],g.prototype,"measurementViewData",void 0),e([o()],g.prototype,"updating",null),e([o()],g.prototype,"view",void 0),g=e([l("esri.views.2d.analysis.AreaMeasurement.AreaMeasurementAreaVisualization")],g);export{g as AreaMeasurementAreaVisualization};
