/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/Handles","../../core/Identifiable","../../core/reactiveUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../Widget","./support/layerListUtils","../support/widget","../support/jsxFactory"],(function(e,t,n,i,s,r,o,l,c,a,d,u,_,p,g){"use strict";const h=e=>Object.freeze(Object.defineProperty({__proto__:null,default:e},Symbol.toStringTag,{value:"Module"})),y={base:"esri-layer-list-panel",content:"esri-layer-list-panel__content",contentLegend:"esri-layer-list-panel__content--legend",contentString:"esri-layer-list-panel__content--string",contentElement:"esri-layer-list-panel__content--html-element",contentWidget:"esri-layer-list-panel__content--widget"},f="legends";let v=function(n){function s(e,t){var s;return(s=n.call(this,e,t)||this)._legend=null,s._handles=new i,s.content=null,s.image=null,s.listItem=null,s.open=!1,s.visible=!0,s}t._inheritsLoose(s,n);var o=s.prototype;return o.initialize=function(){this.own([r.watch((()=>this.content),(e=>this._createLegend(e)),r.initial)])},o.destroy=function(){const{_legend:e}=this;e&&e.destroy(),this._legend=null},o.render=function(){return g.tsx("div",{class:y.base},this._renderContents())},o._renderContent=function(e){const{_legend:t,listItem:n}=this;if(!e)return null;if("legend"===e){return n&&n.view&&n.layer&&t?g.tsx("div",{class:this.classes(y.content,y.contentLegend),key:t},t.render()):null}return"string"==typeof e?g.tsx("div",{class:this.classes(y.content,y.contentString),key:e,innerHTML:e}):p.isWidget(e)?g.tsx("div",{class:this.classes(y.content,y.contentWidget),key:e},e.render()):e instanceof HTMLElement?g.tsx("div",{class:this.classes(y.content,y.contentElement),key:e,bind:e,afterCreate:this._attachToNode}):null},o._renderContents=function(){const{content:e}=this;return Array.isArray(e)?e.map((e=>this._renderContent(e))):this._renderContent(e)},o._getLegendOptions=function(){const{listItem:e}=this;if(!e)return{};const{layer:t,view:n}=e;return t&&n?{view:n,layerInfos:[_.getLegendLayerInfo(t)]}:{}},o._createLegend=function(t){this._hasLegend(t)&&!this._legend&&new Promise(((t,n)=>e(["../Legend"],(e=>t(h(e))),n))).then((({default:e})=>{const{_handles:t,listItem:n}=this,i=new e(this._getLegendOptions());this._legend=i,this.notifyChange("className"),this.notifyChange("title");const s=r.watch((()=>{var e,t;return[null==n?void 0:n.view,null==n?void 0:n.layer,null==n||null==(e=n.layer)?void 0:e.source,null==n||null==(t=n.layer)?void 0:t.parent]}),(()=>this._updateLegend(i)),r.initial);t.add(s,f),this.scheduleRender()}))},o._hasLegend=function(e){const t="legend";return e===t||!!Array.isArray(e)&&e.includes(t)},o._attachToNode=function(e){e.appendChild(this)},o._updateLegend=function(e){e.set(this._getLegendOptions()),this.scheduleRender()},o._getWidget=function(e){return"legend"===e?this._legend:p.isWidget(e)?e:null},o._getFirstWidget=function(){const{content:e}=this;if(Array.isArray(e)){let t=null;return e.some((e=>{const n=this._getWidget(e);return n&&(t=n),!!n})),t}return this._getWidget(e)},t._createClass(s,[{key:"className",get:function(){const{image:e}=this,t=this._getFirstWidget();return this._get("className")||!e&&t?t.iconClass:""},set:function(e){void 0!==e?this._override("className",e):this._clearOverride("className")}},{key:"title",get:function(){const e=this._getFirstWidget();return this._get("title")||e?e.label:""},set:function(e){void 0!==e?this._override("title",e):this._clearOverride("title")}}]),s}(s.IdentifiableMixin(u));n.__decorate([o.property()],v.prototype,"className",null),n.__decorate([o.property()],v.prototype,"content",void 0),n.__decorate([o.property()],v.prototype,"image",void 0),n.__decorate([o.property()],v.prototype,"listItem",void 0),n.__decorate([o.property()],v.prototype,"title",null),n.__decorate([o.property()],v.prototype,"open",void 0),n.__decorate([o.property()],v.prototype,"visible",void 0),v=n.__decorate([d.subclass("esri.widgets.LayerList.ListItemPanel")],v);return v}));
