/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{substitute as t}from"../../../intl.js";import{destroyMaybe as s}from"../../../core/maybe.js";import{watch as i}from"../../../core/reactiveUtils.js";import{property as o,subclass as l}from"../../../core/accessorSupport/decorators.js";import r from"../../Widget.js";import{legendItemCss as c}from"../css.js";import{Statistics as n}from"./Statistics.js";import{getTranslatedLineTitle as a}from"../support/intlUtils.js";import{loadCalciteComponents as d}from"../../support/componentsUtils.js";import{tsx as p}from"../../support/widget.js";let h=class extends r{constructor(e,t){super(e,t),this.checkboxVisible=!0,this.expanded=!1}loadDependencies(){return d({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),checkbox:()=>import("@esri/calcite-components/dist/components/calcite-checkbox"),label:()=>import("@esri/calcite-components/dist/components/calcite-label")})}initialize(){this._statistics=new n(this._statisticsProps),this.addHandles(i(()=>this._statisticsProps,e=>this._statistics.set(e)))}destroy(){this._statistics=s(this._statistics)}render(){const e=this.expanded;return p("div",{class:this.classes(c.base,{[c.disabled]:this.disabled,[c.expanded]:e}),key:this},this._renderColorIndicator(),p("div",{class:c.header,key:"header"},this._renderLabelWithCheckbox(),this._renderCollapseToggleButton()),e?p("div",{class:c.content,key:"content"},this._statistics.render()):null)}get disabled(){return!this.line.available}get _statisticsProps(){return{line:this.line,effectiveUnits:this.effectiveUnits}}_renderColorIndicator(){return p("div",{class:c.colorIndicator,key:"color-indicator",styles:{backgroundColor:this.line.color.toCss()}})}_renderCollapseToggleButton(){const{expanded:e,messages:t}=this,s=e?t.hideDetails:t.showDetails;return p("calcite-action",{bind:this,class:c.collapseToggle,"data-testid":"legend-toggle",icon:e?"chevron-up":"chevron-down",key:"collapse-toggle",scale:"s",text:s,title:s,onclick:this._onCollapseToggleClick})}_onCollapseToggleClick(){this.onExpandedToggle()}_renderLabelWithCheckbox(){const{line:e,checkboxVisible:t,disabled:s,messages:i}=this;return p("calcite-label",{class:c.label,disabled:s,key:`label-${e.id}`,layout:"inline"},t?this._renderCheckbox():null,a(e,i))}_renderCheckbox(){const{disabled:e,line:s,messages:i}=this,o=s.visible,l=o?i.hideProfile:i.showProfile,r=t(l,{name:a(s,i)});return p("calcite-checkbox",{checked:o,class:c.checkbox,disabled:e,title:r,onCalciteCheckboxChange:()=>s.toggleVisibility()})}};e([o()],h.prototype,"checkboxVisible",void 0),e([o()],h.prototype,"disabled",null),e([o({nonNullable:!0})],h.prototype,"effectiveUnits",void 0),e([o()],h.prototype,"expanded",void 0),e([o({nonNullable:!0})],h.prototype,"line",void 0),e([o()],h.prototype,"messages",void 0),e([o()],h.prototype,"onExpandedToggle",void 0),e([o()],h.prototype,"_statistics",void 0),h=e([l("esri.widgets.ElevationProfile.components.LegendItem")],h);export{h as LegendItem};
