/* 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{css as o}from"./css.js";import n from"./LegendElement.js";import{loadCalciteComponents as a}from"../../../support/componentsUtils.js";import{tsx as l,messageBundle as c}from"../../../support/widget.js";const d=768;let h=class extends i{constructor(e,s){super(e,s),this._hasIndicators=!1,this.activeLayerInfos=null,this.headingLevel=3,this.layout="stack",this.messages=null,this.messagesCommon=null,this.type="card",this.view=null}loadDependencies(){return a({carousel:()=>import("@esri/calcite-components/dist/components/calcite-carousel"),"carousel-item":()=>import("@esri/calcite-components/dist/components/calcite-carousel-item")})}render(){this._hasIndicators="auto"===this.layout&&this.view&&this.view.container.clientWidth<=d||"stack"===this.layout;const e=this._hasIndicators?this._renderCarousel():this._renderLayers(),s={[o.stacked]:this._hasIndicators};return l("div",{class:this.classes(o.base,s)},e||l("div",{class:o.message},this.messages.noLegend))}_renderCarousel(){const e=[],t=this.activeLayerInfos;if(t)for(const s of t)this._renderSections(s,e);return e.length?1===e.length?l("div",{class:o.carousel},l("div",{class:o.carouselItem},e[0])):l("calcite-carousel",{class:o.carousel,label:this.messages.carousel},e.map((t,r)=>l("calcite-carousel-item",{class:o.carouselItem,key:r,label:s(this.messagesCommon.pagination.pageText,{index:r+1,total:e.length})},t))):null}_renderLayers(){const e=this.activeLayerInfos,s=e?.toArray()?.map(e=>this._renderLegendForLayer(e)).filter(Boolean);return s?.length?s:null}_renderLegendForLayer(e){if(!e.ready)return null;if(e.children.length){const s=e.children.toArray().map(this._renderLegendForLayer,this);return l("section",{class:this.classes(o.service,o.groupLayer),key:e.layer.uid},l("div",{class:o.serviceCaptionContainer},e.title),s)}return this._renderLegendElementsForLayer(e)}_renderLegendElementsForLayer(e){const s=e.legendElements?.filter(Boolean);if(!s?.length)return null;const t=s.map(s=>l(n,{activeLayerInfo:e,cssEffectFilter:e.cssEffectFilter,hasIndicators:this._hasIndicators,headingLevel:this.headingLevel,isChild:!1,key:`${e.layer.uid}-${s.type}`,layer:e.layer,legendElement:s,messages:this.messages})),r={[o.groupLayerChild]:!!e.parent};return l("section",{class:this.classes(o.service,r),key:e.layer.uid},l("div",{class:o.serviceCaptionContainer},l("div",{class:o.serviceCaptionText},e.title)),l("div",{class:o.serviceContent},t))}_renderSections(e,s){if(!e.ready)return;if(e.children.length)for(const r of e.children)this._renderSections(r,s);const t=e.legendElements;if(t?.length)for(const r of t){const t=l(n,{activeLayerInfo:e,cssEffectFilter:e.cssEffectFilter,hasIndicators:this._hasIndicators,headingLevel:this.headingLevel,isChild:!1,key:`${e.layer.uid}-${r.type}`,layer:e.layer,legendElement:r,messages:this.messages});t&&s.push(t)}}};e([t()],h.prototype,"activeLayerInfos",void 0),e([t()],h.prototype,"headingLevel",void 0),e([t()],h.prototype,"layout",void 0),e([t(),c("esri/widgets/Legend/t9n/Legend")],h.prototype,"messages",void 0),e([t(),c("esri/t9n/common")],h.prototype,"messagesCommon",void 0),e([t({readOnly:!0})],h.prototype,"type",void 0),e([t()],h.prototype,"view",void 0),h=e([r("esri.widgets.Legend.styles.card.CardView")],h);export{h as default};
