const e=window.webmapgl.h;import{b as t}from"./chunk-853b4351.js";class i{constructor(){this.toggle=!1,this.widget="item"}async componentWillLoad(){this.handleStyleId()}async handleStyleId(){let e=await this.getStyle();e&&this.update(e.json)}handleStyleAdded(e){e.detail.id===this.styleId&&this.update(e.detail.json)}handleStyleUpdated(e){e.detail.id===this.styleId&&this.update(e.detail.json)}async getStyle(){let e=document.querySelector(`gl-style#${this.styleId}`);return e&&await e.componentOnReady(),e}getVisible(e){const i=t(this.layers);if(!i||!i.length)return!0;if(!e.layers||!e.layers.length)return!1;for(let t of e.layers)if(-1!==i.indexOf(t.id))return!t.layout||"none"!==t.layout.visibility}async setVisible(e){if(this.visible===e)return;let i=t(this.layers),l=await this.getStyle();if(!l)return;let s=Object.assign({},l.json);s.layers=(s.layers||[]).map(t=>(-1!==i.indexOf(t.id)&&(t.layout=t.layout||{},t.layout.visibility=e?"visible":"none"),t)),l.json=s}update(e){e&&(this.visible=this.getVisible(e))}render(){let t=[];return this.image&&t.push(e("ion-thumbnail",{slot:"start"},e("img",{src:this.image,alt:this.el.textContent}))),t.push(e("ion-label",null,e("slot",null))),this.toggle&&t.push(e("ion-toggle",{slot:"end",checked:this.visible,onIonChange:e=>this.setVisible(e.detail.checked)})),e("divider"===this.widget?"ion-item-divider":"ion-item",null,t)}static get is(){return"gl-legend-item"}static get properties(){return{el:{elementRef:!0},image:{type:String,attr:"image"},layers:{type:String,attr:"layers"},styleId:{type:String,attr:"style-id",watchCallbacks:["handleStyleId"]},toggle:{type:Boolean,attr:"toggle"},visible:{state:!0},widget:{type:String,attr:"widget"}}}static get listeners(){return[{name:"body:glStyleElementAdded",method:"handleStyleAdded"},{name:"body:glStyleElementModified",method:"handleStyleUpdated"}]}static get style(){return"gl-legend-item .item ion-thumbnail{height:40px;width:40px}"}}export{i as GlLegendItem};