/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{substitute as s}from"../../../../intl.js";import{property as t,subclass as r}from"../../../../core/accessorSupport/decorators.js";import i from"../../../Widget.js";import l from"./ColorRamp.js";import{css as a}from"./css.js";import n from"./SizeRamp.js";import o from"./UnivariateAboveAndBelowRamp.js";import m from"./UnivariateColorSizeRamp.js";import{renderRelationshipRamp as c}from"../support/relationshipUtils.js";import{getLegendElementTitle as p,getPreviewAriaLabelIntl as h}from"../support/utils.js";import{attachToNode as y,isImageryStretchedLegend as d,getTitle as g}from"../../support/styleUtils.js";import{tsx as f}from"../../../support/widget.js";var u;let b=u=class extends i{constructor(e,s){super(e,s),this.cssEffectFilter=null,this.isChild=!1,this.legendElement=null}render(){const e=this._renderLegendElement(),s=p(this.legendElement,this.messages),t=this.isChild?a.layerChildTable:a.layerTable,r=s?f("div",{class:a.layerCaption},s):null,i={[a.layerTableSizeRamp]:"size-ramp"===this.legendElement.type||!this.isChild};return f("section",{class:this.classes(t,i),key:`${this.key}-table`},r,e)}_renderLegendElement(){switch(this.legendElement.type){case"symbol-table":return this._renderSymbolTable(this.legendElement);case"size-ramp":return f(n,{key:this.key,legendElement:this.legendElement,messages:this.messages});case"color-ramp":case"opacity-ramp":case"heatmap-ramp":case"stretch-ramp":return f(l,{key:this.key,legendElement:this.legendElement,messages:this.messages,opacity:this.layer.opacity});case"relationship-ramp":return c(this.legendElement,this.id,{opacity:this.layer.opacity,cssEffectFilter:this.cssEffectFilter,ariaLabel:this.messages.previewRelationshipRampAriaLabel,key:this.key});case"pie-chart-ramp":{const{preview:e}=this.legendElement;if(!e)return null;const t=s(this.messages.previewPieChartAriaLabel,{label:null});return t&&e.querySelector("svg")?.setAttribute("aria-label",t),f("div",{afterCreate:y,bind:e,key:`${this.key}-preview`})}case"univariate-above-and-below-ramp":return f(o,{cssEffectFilter:this.cssEffectFilter,key:this.key,legendElement:this.legendElement,messages:this.messages,opacity:this.layer.opacity});case"univariate-color-size-ramp":return f(m,{cssEffectFilter:this.cssEffectFilter,key:this.key,legendElement:this.legendElement,messages:this.messages,opacity:this.layer.opacity});default:return null}}_renderSymbolTable(e){const s=e.infos.map(s=>this._renderElementInfo(s,e.legendType)).filter(Boolean);return s.length?f("div",{class:a.layerBody},s):null}_renderElementInfo(e,s){const{layer:t}=this,r="label"in e?e.label:null,i=`${this.key}-${r}`;if("type"in e&&e.type)return f(u,{cssEffectFilter:this.cssEffectFilter,isChild:!0,key:i,layer:t,legendElement:e,messages:this.messages});if(!("preview"in e&&e.preview||"src"in e&&e.src))return null;const l=d(t,s),n={[a.imageryLayerInfoStretched]:l},o={[a.imageryLayerInfoStretched]:l};return f("div",{class:a.layerRow,key:`${i}-row`},f("div",{class:this.classes(a.symbolContainer,o)},this._renderPreview(e,l)),f("div",{class:this.classes(a.layerInfo,n)},g(this.messages,r,!1)||""))}_renderPreview(e,s){const{layer:t}=this;if("preview"in e&&e.preview){const{preview:s}=e,t="previewAriaLabel"in e?e.previewAriaLabel:null,r="label"in e?g(this.messages,e.label,!1):null,i=s.querySelector("svg"),l=h(this.messages,t||r);return l&&i&&i.setAttribute("aria-label",l),f("div",{afterCreate:y,bind:s,class:a.symbol})}return"src"in e&&e.src?this._renderImage(e,t,s):null}_renderImage(e,s,t){const{previewAriaLabel:r,src:i,opacity:l}=e,n=g(this.messages,e.label,!1),o={[a.imageryLayerStretchedImage]:t,[a.symbol]:!t},m={opacity:`${l??s.opacity}`},c=h(this.messages,r||n);return f("img",{alt:c,"aria-label":c,border:0,class:this.classes(o),height:e.height,src:i,styles:m,width:e.width})}};e([t()],b.prototype,"cssEffectFilter",void 0),e([t()],b.prototype,"isChild",void 0),e([t()],b.prototype,"layer",void 0),e([t()],b.prototype,"legendElement",void 0),e([t()],b.prototype,"messages",void 0),b=u=e([r("esri.widgets.Legend.styles.classic.LegendElement")],b);export{b as default};
