/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as i}from"tslib";import{onLocaleChange as e,fetchMessageBundle as t}from"../../../../intl.js";import s from"../../../../core/Accessor.js";import{destroyHandle as a}from"../../../../core/handleUtils.js";import"../../../../core/has.js";import{mapCollection as r}from"../../../../core/mapCollectionUtils.js";import{watch as o,syncAndInitial as n,when as l,sync as m}from"../../../../core/reactiveUtils.js";import{pt2px as c}from"../../../../core/screenUtils.js";import{property as h,subclass as d}from"../../../../core/accessorSupport/decorators.js";import{ZEROS as p}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{LengthDimensionVisualization as u}from"./LengthDimensionVisualization.js";import{markerLineSizeFraction as f,offsetLineSizeFraction as M}from"./settings.js";import{LineMarkerMaterial as g}from"../../webgl-engine/materials/LineMarkerMaterial.js";import{createStipplePatternSimple as _}from"../../webgl-engine/materials/lineStippleUtils.js";import{RibbonLineMaterial as y}from"../../webgl-engine/materials/RibbonLineMaterial.js";let w=class extends s{get analysis(){return this.analysisViewData.analysis}get visible(){return this.analysisViewData.visible}constructor(i){super(i),this.loadingMessages=!1,this._messages=null}initialize(){const i=this.isDecoration,t=this.view.state.isGlobal;this._markerMaterial=new g({width:1,anchor:1,color:p,placement:"begin-end",worldSpace:!0,hideOnShortSegments:!0,hasTip:!0,renderOccluded:4,markerPrimitive:"triangle",isDecoration:i},t),this._dimensionLineMaterial=new y({width:1,color:p,renderOccluded:4,markerParameters:this._markerMaterial.parameters,isDecoration:i},t),this._offsetLineMaterial=new y({width:1,color:p,renderOccluded:4,stipplePattern:_(5),isDecoration:i},t),this._smallDimensionLineMaterial=new y({width:1,color:p,renderOccluded:4,isDecoration:i},t),this._smallOffsetLineMaterial=new y({width:1,color:p,renderOccluded:4,stipplePattern:_(5),isDecoration:i},t);const s=r(()=>this.analysisViewData.computations,({computation:i})=>this._createVisualization(i));this._dimensionVisualizations=s,this.addHandles([a(s),o(()=>this.analysis.style.color.toUnitRGBA(),i=>{for(const e of this._lineMaterials())e.setParameters({color:i})},n),o(()=>this.analysis.style.lineSize,i=>{const e=c(i);this._markerMaterial.setParameters({width:e*f}),this._dimensionLineMaterial.setParameters({width:e,markerParameters:this._markerMaterial.parameters});const t=Math.max(e*M,1);this._offsetLineMaterial.setParameters({width:t})},n),o(()=>({camera:this.view.state.camera,style:v(this.analysis)}),({camera:i,style:e})=>{for(const{visualization:t}of this._dimensionVisualizations)t.updateCameraDependentElements(i,t.computation.geometry,e),t.updateLabelStyle(e)}),o(()=>this.visible,i=>{for(const{visualization:e}of this._dimensionVisualizations)e.visible=i})]),this.addHandles([e(()=>this._updateMessageBundle()),l(()=>!this.loadingMessages,()=>{for(const{visualization:i}of this._dimensionVisualizations)i.updateUnitsMessages(this._messages)},m)]),this._updateMessageBundle()}get testInfo(){}_createVisualization(i){const e=new u({analysis:this.analysis,computation:i,view:this.view,visible:this.visible,markerMaterial:this._markerMaterial,dimensionLineMaterial:this._dimensionLineMaterial,offsetLineMaterial:this._offsetLineMaterial,smallDimensionLineMaterial:this._smallDimensionLineMaterial,smallOffsetLineMaterial:this._smallOffsetLineMaterial,messages:this._messages,isDecoration:this.isDecoration});return{visualization:e,remove:()=>e.destroy()}}_lineMaterials(){return[this._markerMaterial,this._dimensionLineMaterial,this._offsetLineMaterial,this._smallDimensionLineMaterial,this._smallOffsetLineMaterial]}async _updateMessageBundle(){this.loadingMessages=!0;try{this._messages=await t("esri/core/t9n/Units")}finally{this.loadingMessages=!1}}};function v(i){const{fontSize:e,lineSize:t,textColor:s,textBackgroundColor:a}=i.style;return{fontSize:e,lineSize:t,textBackgroundColor:a.clone(),textColor:s.clone()}}i([h({constructOnly:!0})],w.prototype,"analysisViewData",void 0),i([h({constructOnly:!0,nonNullable:!0})],w.prototype,"view",void 0),i([h({constructOnly:!0})],w.prototype,"isDecoration",void 0),i([h()],w.prototype,"analysis",null),i([h()],w.prototype,"visible",null),i([h()],w.prototype,"loadingMessages",void 0),w=i([d("esri.views.3d.analysis.Dimension.DimensionVisualization")],w);export{w as DimensionVisualization};
