/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{c as m}from"./KZUFDOJ2.js";import{b as r,e as c}from"./EH5576ZY.js";import{a as u}from"./ZNBKMZP7.js";import{M as h,b as a,x as i,z as l}from"./GRFF5Y4R.js";export default $arcgis.t(([{when:E,watch:g}])=>{var d=class extends l{constructor(t){super(t),this.direction=c(),this.popupRef=h(),this.attributionHeight=0,this._uiContainer=null,this.component.listen("arcgisViewClick",o=>{this._handleOpenPopup(o.detail)}),this.component.listenOn(globalThis,"unhandledrejection",o=>{if(o.reason?.name==="webgl:required"){let{name:e}=o.reason;this.webGLError={name:e}}})}hostLifecycle(){return[E(()=>this.component.view.ready,()=>{this._assignDefaultPopup()}),E(()=>this.component.view.popup?.visible,()=>{this.popupElement?.open&&(this.popupElement.open=!1)})]}async openPopup(t){if(this._assignDefaultPopup(),this.closePopup(),this.popupElement){await this.popupElement.componentOnReady(),this.popupElement.open=!0;let{fetchFeatures:o}=t;delete t.fetchFeatures,Object.assign(this.popupElement,t),o&&this.popupElement.fetchFeatures()}else await this.component.view.openPopup(t)}closePopup(){this.popupElement&&(this.popupElement.open=!1),this.component.view.closePopup()}_assignDefaultPopup(){this.popupRef.value&&!this.popupElement&&(this.popupElement=this.popupRef.value,this.popupElement.referenceElement=this.component.el,this.popupElement.view=this.component.view)}handleAttributionHeightChange(t){if(!(this.attributionHeight===t||!this.component.el.shadowRoot)){if(this.attributionHeight=t,!this._uiContainer){let o=this.component.el.shadowRoot.querySelector(".arcgis-map-container-ui");this._uiContainer=o}this._uiContainer?.style.setProperty("--arcgis-internal-attribution-space-top",`${this.attributionHeight}px`)}}async _handleOpenPopup(t){if(this._assignDefaultPopup(),this.popupElement&&!this.component.popupDisabled){t.stopPropagation();let{location:o,promises:e}=await this.popupElement.handleViewClick(t);e?.length&&this.openPopup({location:o,promises:e})}}_handlePopupSlotChange(t){let o=u(t.target,"arcgis-popup");!this.popupElement&&o.length?this.popupElement=o[0]:o.length||(this.popupElement=void 0)}_webGLErrorAlert(){return this.webGLError?a`<arcgis-webgl-error .errorName=${this.webGLError.name}></arcgis-webgl-error>`:null}render(){return m({direction:this.direction,popupComponentEnabled:this.component.popupComponentEnabled,handlePopupSlotChange:t=>this._handlePopupSlotChange(t),webGLErrorElement:this._webGLErrorAlert(),popupElement:this.popupRef})}},_=r((p,t)=>{let o=i();return t.onLifecycle(()=>g(()=>{let{map:e}=p;if(!e||e.destroyed)return[];let n=[];return e.loadError&&n.push(e),e.basemap?.loadError&&n.push(e.basemap),e.ground.loadError&&n.push(e.ground),[...e.allLayers,...e.allTables].forEach(s=>{s.loadError&&n.push(s)}),n},e=>{e.length&&(p.loadErrorSources=e,o.emit())})),o}),L=r((p,t)=>{let o=i();return t.onLifecycle(()=>g(()=>p.view?.readyState,e=>{(e==="map-content-error"||e==="rendering-error")&&o.emit()})),o});return{a:d,b:_,c:L}},"core/reactiveUtils")