/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{a as y}from"./TCUNTTNI.js";import b from"./7JC52SFZ.js";import a from"./4AFANEZZ.js";import{a as _}from"./IADXB53D.js";import{a as l}from"./ONARC6AZ.js";import{a as w}from"./BM4VSEDV.js";import{b as v}from"./HVT2WBVC.js";import"./UBPOT5V3.js";import"./ISFTCFSJ.js";import{E as p,F as g,G as f,I as c,h,i as o,t as m}from"./FFF5HUPM.js";import"./EXBEKVP5.js";export default $arcgis.t(([n,L,b,I,,{b:u}])=>{var C=h`@layer{instant-apps-interactive-legend{display:block;height:100%}instant-apps-interactive-legend .esri-legend{height:100%;background-color:var(--calcite-color-foreground-1)!important;color:var(--calcite-color-text-1)!important}instant-apps-interactive-legend .esri-legend.esri-component.esri-widget.esri-widget--panel{margin:0}instant-apps-interactive-legend .esri-legend__layer,instant-apps-interactive-legend .esri-legend__layer-body{margin-left:0!important}instant-apps-interactive-legend .esri-legend__layer-row{box-sizing:border-box!important}}`,$={esri:{base:"esri-legend",widget:"esri-widget",widgetPanel:"esri-widget--panel",component:"esri-component"}},d=class extends f{constructor(){super(...arguments),this._messages=w({name:"instant-apps-interactive-legend"}),this.ref=p(),this.zoomTo=!1,this.featureCount=!1,this.filterMode={type:y.FILTER},this.compact=!1}static{this.properties={handles:16,legendvm:16,view:0,zoomTo:5,featureCount:5,filterMode:0,compact:5}}static{this.styles=C}static{this.shadowRootOptions=m}async load(){this.compactHandler(),new MutationObserver(()=>{this.requestUpdate()}).observe(this.el,{attributes:!0}),await this.initializeModules()}willUpdate(e){(e.has("handles")||e.has("view"))&&this.init(),e.has("compact")&&(this.hasUpdated||this.compact)&&this.compactHandler()}async initializeModules(){this.handles=new L;let e=new b({});return await n.whenOnce(()=>e?.messages),this._messages={...this._messages,...e.messages},await Promise.resolve()}async init(){if(!(!this.view||!this.handles))try{let{on:e,whenOnce:i}=n,s=this.view?.map?.allLayers?.map(async r=>await r.load());await Promise.allSettled(s),await i(()=>this.view?.ready);let t={view:this.view,respectLayerDefinitionExpression:!0},a=new I(t);this.legendvm=a,this.handles.add([e(()=>this.legendvm?.activeLayerInfos,"change",()=>this._refreshActiveLayerInfos(this?.legendvm?.activeLayerInfos))])}catch(e){console.error('Failed at "init": ',e)}}compactHandler(){u.set("compact",this.compact)}_refreshActiveLayerInfos(e){e&&(this.handles.removeAll(),e.forEach(i=>this._renderOnActiveLayerInfoChange(i)))}render(){let{base:e,component:i,widget:s,widgetPanel:t}=$.esri,a=[e,i,s,t].filter(Boolean).map(r=>r).join(" ");return l("interactive-legend",o`<div class=${c(a)}>${this.legendvm?l("interactive-legend-classic",o`<instant-apps-interactive-legend-classic class=${c(_(this.el))} .legendvm=${this.legendvm} .zoomTo=${this.zoomTo} .filterMode=${this.filterMode} .featureCount=${this.featureCount} .messages=${this._messages} ${g(this.ref)}></instant-apps-interactive-legend-classic>`):null}</div>`)}_renderOnActiveLayerInfoChange(e){let{on:i}=n,s=i(()=>e.children,"change",()=>e.children.forEach(t=>this._renderOnActiveLayerInfoChange(t)));this.handles.add(s,`children_${e?.layer?.uid}`),e.children.forEach(t=>{this._renderOnActiveLayerInfoChange(t),t?.children?.length>0&&t?.children?.forEach(a=>this._renderOnActiveLayerInfoChange(a))})}};v("instant-apps-interactive-legend",d);return d},"core/reactiveUtils","core/Handles","widgets/Legend","widgets/Legend/LegendViewModel",a,b)