/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../chunks/_rollupPluginBabelHelpers","../chunks/tslib.es6","../core/Handles","../core/maybe","../core/reactiveUtils","../core/accessorSupport/decorators/aliasOf","../core/arrayUtils","../core/has","../core/accessorSupport/decorators/cast","../core/accessorSupport/decorators/property","../core/accessorSupport/decorators/subclass","./Widget","./Legend/LegendViewModel","./Legend/styles/Card","./Legend/styles/Classic","./support/widgetUtils","./support/decorators/messageBundle","./support/jsxFactory"],(function(e,t,r,i,s,o,a,n,d,l,c,p,y,h,v,u,f,g){"use strict";const _={base:"esri-legend",widget:"esri-widget",panel:"esri-widget--panel",widgetIcon:"esri-icon-layer-list"};let w=function(t){function o(e,i){var s;return(s=t.call(this,e,i)||this)._handles=new r,s.activeLayerInfos=null,s.basemapLegendVisible=!1,s.groundLegendVisible=!1,s.headingLevel=3,s.hideLayersNotInCurrentView=!1,s.keepCacheOnDestroy=!1,s.respectLayerVisibility=!0,s.iconClass=_.widgetIcon,s.label=void 0,s.layerInfos=null,s.messages=null,s.style=new v,s.view=null,s.viewModel=new y,s}e._inheritsLoose(o,t);var a=o.prototype;return a.initialize=function(){this.own([s.on((()=>this.view),"resize",(()=>this.scheduleRender())),s.on((()=>this.activeLayerInfos),"change",(()=>this._refreshActiveLayerInfos(this.activeLayerInfos))),s.watch((()=>this.headingLevel),(e=>{const{style:t}=this;t&&(t.headingLevel=e)})),s.watch((()=>this.style),((e,t)=>{t&&e!==t&&t.destroy(),e&&(e.activeLayerInfos=this.activeLayerInfos,"card"===e.type&&(e.view=this.view),e.headingLevel=this.headingLevel)}),s.initial)])},a.destroy=function(){this._handles=i.destroyMaybe(this._handles)},a.castStyle=function(e){if(e instanceof h||e instanceof v)return e;if("string"==typeof e)return"card"===e?new h:new v;if(e&&"string"==typeof e.type){const t={...e};delete t.type;return new("card"===e.type?h:v)(t)}return new v},a.render=function(){return g.tsx("div",{class:this.classes(_.base,_.widget,this.style instanceof v?_.panel:null)},this.style.render())},a._refreshActiveLayerInfos=function(e){this._handles.removeAll(),e.forEach((e=>this._renderOnActiveLayerInfoChange(e))),this.scheduleRender()},a._renderOnActiveLayerInfoChange=function(e){const t=s.watch((()=>e.version),(()=>this.scheduleRender()));this._handles.add(t,`version_${e.layer.uid}`);const r=s.on((()=>e.children),"change",(()=>e.children.forEach((e=>this._renderOnActiveLayerInfoChange(e)))),s.initial);this._handles.add(r,`children_${e.layer.uid}`),e.children.forEach((e=>this._renderOnActiveLayerInfoChange(e)))},o}(p);t.__decorate([o.aliasOf("viewModel.activeLayerInfos")],w.prototype,"activeLayerInfos",void 0),t.__decorate([o.aliasOf("viewModel.basemapLegendVisible")],w.prototype,"basemapLegendVisible",void 0),t.__decorate([o.aliasOf("viewModel.groundLegendVisible")],w.prototype,"groundLegendVisible",void 0),t.__decorate([l.property()],w.prototype,"headingLevel",void 0),t.__decorate([o.aliasOf("viewModel.hideLayersNotInCurrentView")],w.prototype,"hideLayersNotInCurrentView",void 0),t.__decorate([o.aliasOf("viewModel.keepCacheOnDestroy")],w.prototype,"keepCacheOnDestroy",void 0),t.__decorate([o.aliasOf("viewModel.respectLayerVisibility")],w.prototype,"respectLayerVisibility",void 0),t.__decorate([l.property()],w.prototype,"iconClass",void 0),t.__decorate([l.property({aliasOf:{source:"messages.widgetLabel",overridable:!0}})],w.prototype,"label",void 0),t.__decorate([o.aliasOf("viewModel.layerInfos")],w.prototype,"layerInfos",void 0),t.__decorate([l.property(),f.messageBundle("esri/widgets/Legend/t9n/Legend")],w.prototype,"messages",void 0),t.__decorate([l.property()],w.prototype,"style",void 0),t.__decorate([d.cast("style")],w.prototype,"castStyle",null),t.__decorate([o.aliasOf("viewModel.view")],w.prototype,"view",void 0),t.__decorate([l.property()],w.prototype,"viewModel",void 0),w=t.__decorate([c.subclass("esri.widgets.Legend")],w);return w}));
