/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../core/Accessor.js";import{createTask as s}from"../../core/asyncUtils.js";import{makeHandle as o}from"../../core/handleUtils.js";import{isNone as i,isSome as r,applySome as a}from"../../core/maybe.js";import{throwIfAborted as n}from"../../core/promiseUtils.js";import{formatLength as l}from"../../core/quantityFormatUtils.js";import{watch as c,on as p}from"../../core/reactiveUtils.js";import{createScreenPointArray as h}from"../../core/screenUtils.js";import{getDefaultUnitForView as d}from"../../core/unitUtils.js";import{property as m}from"../../core/accessorSupport/decorators/property.js";import"../../core/arrayUtils.js";import"../../core/accessorSupport/ensureType.js";import{subclass as u}from"../../core/accessorSupport/decorators/subclass.js";import{k as b,s as f,f as g,b as _,l as x,j as y}from"../../chunks/vec2.js";import{a as v}from"../../chunks/vec2f64.js";import{F as j}from"../../chunks/vec3.js";import{isClockwise as U}from"../../geometry/support/coordsUtils.js";import{fetchMessageBundle as I}from"../../intl/messages.js";import{getGeometryEffectiveElevationMode as L}from"../../support/elevationInfoUtils.js";import D from"../overlay/TextOverlayItem.js";import{autoDirectDistanceByElevationMode as O}from"../support/automaticLengthMeasurementUtils.js";const S=3025,w={default:15,far:25};let P=class extends t{constructor(e){super(e),this.context=null,this.stagedVertex=null,this.visible=!0,this.edgeDistance="default",this._messagesUnits=null,this._labelInfos=[],this._nextLabelIndex=0}initialize(){const e=s((async e=>{const t=await I("esri/core/t9n/Units");n(e),this._messagesUnits=t})),t=()=>a(this.context,(e=>e.editGeometryOperations));this.addHandles([c((()=>[r(this.context)&&this.getCameraOrExtent(this.context),this.visible,this._edgeDistancePixels,this.stagedVertex,this._messagesUnits]),(()=>this._update())),...["vertex-add","vertex-update","vertex-remove"].map((e=>p(t,e,(()=>this._update())))),o((()=>e.abort()))])}destroy(){for(this._nextLabelIndex=0;this._labelInfos.length;)this._destroyLabel(this._labelInfos.pop())}get updating(){return i(this._messagesUnits)}get test(){return{labelContents:this._labelInfos.slice(0,this._nextLabelIndex).map((e=>e.label.text))}}get _edgeDistancePixels(){return w[this.edgeDistance]}_update(){this._nextLabelIndex=0;const e=this.context;if(i(e))return void this._destroyUnusedLabels();const{components:t,geometry:s,coordinateHelper:o}=e.editGeometryOperations.data;if(!s)return void this._destroyUnusedLabels();const a=t.length;for(let i=0;i{n.push(o.toXYZ(e.pos))})),0===i&&r(this.stagedVertex)&&n.push(o.toXYZ(this.stagedVertex)),n.length<2)continue;const l=n[0],c=n[n.length-1];"polygon"===s.type&&n.length>2&&!j(l,c)&&n.push(l);const p=1===a&&!U(n,!1,!1);let h=C,d=G;this.toScreenPointArray(e,l,h);for(let t=1;tMath.abs(V[1])?n.anchor=V[0]>0?"left":"right":n.anchor=-V[1]<0?"top":"bottom"}_getOrCreateLabel(e){if(this._labelInfos.length>this._nextLabelIndex)return this._labelInfos[this._nextLabelIndex++];const t=new D({fontSize:10,anchor:"center"});e.view.overlay.items.add(t);const s={label:t};return this._labelInfos.push(s),this._nextLabelIndex=this._labelInfos.length,s}_destroyUnusedLabels(){for(;this._labelInfos.length>this._nextLabelIndex;)this._destroyLabel(this._labelInfos.pop())}_destroyLabel({label:e}){a(this.context,(t=>t.view.overlay.items.remove(e))),e.destroy()}};e([m()],P.prototype,"context",void 0),e([m()],P.prototype,"stagedVertex",void 0),e([m()],P.prototype,"visible",void 0),e([m()],P.prototype,"edgeDistance",void 0),e([m()],P.prototype,"updating",null),e([m()],P.prototype,"_messagesUnits",void 0),e([m()],P.prototype,"_edgeDistancePixels",null),P=e([u("esri.views.interactive")],P);const V=v(),k=v(),C=h(),G=h();export{P as SegmentLabels};