/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{property as t,subclass as i}from"../../../../core/accessorSupport/decorators.js";import{SketchTooltipInfo as l}from"./SketchTooltipInfo.js";let s=class extends l{constructor(e){super(e),this.type="dynamic",this.getActiveHandle=null,this.renderContext=null,this._isVisibleField=e=>{if(!e.visible)return!1;const t=e.name;switch(t){case"x":case"y":return this.visibleElements.coordinates;default:return this.visibleElements[t]??!0}}}get availableFields(){return this.getAllFields?.()?.map(e=>e.field)??[]}get availableFieldsForCurrentHandle(){const e=this.getAllFields?.(),t=this.getActiveHandle?.();return a(e??[],t)}get allManagedFields(){const{availableFieldsForCurrentHandle:e}=this,t=this.getActiveHandle?.(),i=this._getXyMode(t);return(this._useCoordinateDisplay(t,i)?e.filter(e=>o(e.field)):this._useDirectionDistanceDisplay(t,i)?e.filter(e=>r(e.field)):e).filter(e=>this._isVisibleField(e.field)).sort((e,t)=>n(e.field,t.field))}get fieldsGroupedForDisplay(){const e=this.allManagedFields,t=new Map,i=[];for(const l of e){const e=l.displayGroup;t.has(e)||t.set(e,[]),t.get(e)?.push(l)}for(const[l,s]of t.entries())if(2===s.length&&l){const e=s.toSorted((e,t)=>n(e.field,t.field));i.push({left:e[0].field,right:e[1].field})}else i.push(...s.map(e=>e.field));return i}get xyMode(){return this._getXyMode(this.getActiveHandle?.())}get allFields(){return this.allManagedFields.map(e=>e.field)}getConstraintFieldsForHandle(e){const t=this.getAllFields?.(),i=this._getXyMode(e),l=a(t??[],e).map(e=>e.field).filter(d);return(this._useCoordinateDisplay(e,i)?l.filter(o):this._useDirectionDistanceDisplay(e,i)?l.filter(r):l).filter(this._isVisibleField)}isEffectiveVisibleField(e){const{allFields:t,renderContext:i}=this;return e.visible&&!!i&&t.includes(e)}_getXyMode(e){const t=this.sketchOptions.tooltips.xyMode,i=e?.editSession?.endVertex?.leftSegment?.leftVertex;return"auto"===t?i&&"primary"===e?.role?"direction-distance":"coordinates":t}_useCoordinateDisplay(e,t){const{availableFields:i}=this;return("coordinates"===t||"secondary"===e?.role)&&i.some(e=>"x"===e.name)&&i.some(e=>"y"===e.name)}_useDirectionDistanceDisplay(e,t){const{availableFields:i}=this;return"direction-distance"===t&&"primary"===e?.role&&i.some(e=>"distance"===e.name)&&i.some(e=>"direction"===e.name)}};function n(e,t){return e.displayOrder-t.displayOrder}function o(e){return"direction"!==e.name&&"distance"!==e.name}function r(e){return"x"!==e.name&&"y"!==e.name}function a(e,t){const{name:i,role:l}=t??{};return e?.filter(e=>!(null!=e.appliesToHandlesWithName&&e.appliesToHandlesWithName!==i||null!=e.appliesToHandlesWithRole&&e.appliesToHandlesWithRole!==l))??[]}function d(e){switch(e.name){case"direction":case"distance":case"elevation":case"x":case"y":return!0;default:return!1}}e([t()],s.prototype,"type",void 0),e([t()],s.prototype,"getAllFields",void 0),e([t()],s.prototype,"getActiveHandle",void 0),e([t()],s.prototype,"availableFields",null),e([t()],s.prototype,"availableFieldsForCurrentHandle",null),e([t()],s.prototype,"allManagedFields",null),e([t()],s.prototype,"fieldsGroupedForDisplay",null),e([t()],s.prototype,"xyMode",null),e([t()],s.prototype,"allFields",null),e([t()],s.prototype,"renderContext",void 0),s=e([i("esri.views.interactive.tooltip.infos.DynamicTooltipInfo")],s);export{s as DynamicTooltipInfo};
