/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{watch as t}from"../../../../core/reactiveUtils.js";import{property as i,subclass as s}from"../../../../core/accessorSupport/decorators.js";import{SketchTooltipInfo as l}from"./SketchTooltipInfo.js";let o=class extends l{constructor(e){super(e),this.type="dynamic",this.renderContext=null,this.helpMessage=void 0,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}}}initialize(){this.addHandles(t(()=>this.getHelpMessageKey?.(),e=>this.helpMessage=e??void 0))}get availableFields(){return this.getAllFields?.()?.map(e=>e.field)??[]}get availableFieldsForCurrentHandle(){const e=this.getAllFields?.(),t=this.getActiveHandle?.();return d(e??[],t)}get allManagedFields(){const{availableFieldsForCurrentHandle:e}=this,t=this.getActiveHandle?.(),i=this._getXyMode(t);return(this._useCoordinateDisplay(t,i)?e.filter(e=>n(e.field)):this._useDirectionDistanceDisplay(t,i)?e.filter(e=>a(e.field)):e).filter(e=>this._isVisibleField(e.field)).sort((e,t)=>r(e.field,t.field))}get fieldsGroupedForDisplay(){const e=this.allManagedFields,t=new Map,i=[];for(const s of e){const e=s.displayGroup;t.has(e)||t.set(e,[]),t.get(e)?.push(s)}for(const[s,l]of t.entries())if(2===l.length&&s){const e=l.toSorted((e,t)=>r(e.field,t.field));i.push({left:e[0].field,right:e[1].field})}else i.push(...l.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),s=d(t??[],e).map(e=>e.field).filter(p);return(this._useCoordinateDisplay(e,i)?s.filter(n):this._useDirectionDistanceDisplay(e,i)?s.filter(a):s).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 r(e,t){return e.displayOrder-t.displayOrder}function n(e){return"direction"!==e.name&&"distance"!==e.name}function a(e){return"x"!==e.name&&"y"!==e.name}function d(e,t){const{name:i,role:s}=t??{};return e?.filter(e=>!(null!=e.appliesToHandlesWithName&&e.appliesToHandlesWithName!==i||null!=e.appliesToHandlesWithRole&&e.appliesToHandlesWithRole!==s))??[]}function p(e){switch(e.name){case"direction":case"distance":case"elevation":case"x":case"y":return!0;default:return!1}}e([i()],o.prototype,"type",void 0),e([i()],o.prototype,"getAllFields",void 0),e([i()],o.prototype,"getActiveHandle",void 0),e([i()],o.prototype,"getHelpMessageKey",void 0),e([i()],o.prototype,"availableFields",null),e([i()],o.prototype,"availableFieldsForCurrentHandle",null),e([i()],o.prototype,"allManagedFields",null),e([i()],o.prototype,"fieldsGroupedForDisplay",null),e([i()],o.prototype,"xyMode",null),e([i()],o.prototype,"allFields",null),e([i()],o.prototype,"renderContext",void 0),e([i()],o.prototype,"helpMessage",void 0),o=e([s("esri.views.interactive.tooltip.infos.DynamicTooltipInfo")],o);export{o as DynamicTooltipInfo,p as isKnownConstraintField};
