import{html as t,LitElement as e}from"../../../../../lit/index.js";import{store as i}from"../../core/haxcms-site-store.js";import{autorun as s,toJS as n}from"../../../../../mobx/dist/mobx.esm.js";class SiteRegion extends e{static get tag(){return"site-region"}static get properties(){return{name:{type:String},contentItemIds:{type:Array}}}constructor(){super(),this.name=null,this.__disposer=this.__disposer?this.__disposer:[],s((t=>{const e=n(i.regionData);this.name&&e[this.name]&&(this.contentItemIds=e[this.name]),this.__disposer.push(t)}))}updated(t){t.forEach(((t,e)=>{if(this.shadowRoot){if("name"===e&&this[e]){const t=n(i.regionData);t[this.name]&&(this.contentItemIds=t[this.name])}"contentItemIds"===e&&this[e]&&this[e].length>0&&(clearTimeout(this.__debounce),this.__debounce=setTimeout((async()=>{this.innerHTML="",await this.contentItemIds.map((async t=>{let e=i.findItem(t);e&&e.location&&await fetch(e.location,{method:"GET",priority:"low"}).then((t=>{if(t.ok)return t.text()})).then((t=>{let e=globalThis.document.createElement("div");e.innerHTML=t,e.classList.add("site-region-wrapper"),e.setAttribute("part",`site-region-wrapper-${this.name}`),this.appendChild(e)})).catch((t=>{console.error("region data not found")}))}))}),100))}}))}render(){return t`<slot></slot>`}}customElements.define(SiteRegion.tag,SiteRegion);