/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.34/esri/copyright.txt for details.
v4.34.7 */
import{a as u}from"./B7UYEEQJ.js";import"./SRDD32D4.js";import"./IMJMO6DB.js";import{J as y,P as d,b as l,s as c}from"./RNRMSLW5.js";import"./G6QKOIC3.js";var n="map-components:arcgis-utility-network-result-feature-list",o=class extends y{constructor(){super(...arguments),this._layerByLayerId=new Map,this._messages=u({blocking:!0}),this._compareByLayerTitle=([e],[t])=>{let s=this._getLayerBySourceId(e),r=this._getLayerBySourceId(t),i=s?.title??"",a=r?.title??"";return i.localeCompare(a,void 0,{numeric:!0})},this._state="ready",this.elements=[],this.layers=[],this.arcgisSelectedLayerChange=c(),this._renderLayerListItem=([e,t])=>{let{utilityNetwork:s,_messages:r}=this,i=s.getLayerIdBySourceId(e),a=this._getLayerByLayerId(i),h=a?.title||r.unknown;return l`<calcite-list-item .label=${h} @calciteListItemSelect=${()=>this._selectedLayer=a}><calcite-chip .label=${r.labels.numberOfElements} slot=content-end>${t.toString()}</calcite-chip><calcite-icon icon=chevron-right slot=content-end></calcite-icon></calcite-list-item>`}}static{this.properties={_selectedLayer:16,_state:16,elements:0,layers:0,messageOverrides:0,selectedLayer:32,utilityNetwork:0}}get _sourceIdToFeatureCount(){let e=new Map;return this.elements.forEach(t=>{let s=e.get(t.networkSourceId);s==null?e.set(t.networkSourceId,1):e.set(t.networkSourceId,s+1)}),e}get selectedLayer(){return this._selectedLayer}willUpdate(e){e.has("_selectedLayer")&&this.arcgisSelectedLayerChange.emit(),(e.has("layers")||e.has("utilityNetwork"))&&this._loadDependencies()}load(){this._loadDependencies()}loaded(){this.elements.length===0&&console.warn(`${n} was rendered without any elements set for the \`elements\` property.`),this.utilityNetwork||console.warn(`${n} was rendered without the required \`utilityNetwork\` property.`),this.layers.length===0&&console.warn(`${n} was rendered without any layers set for the \`layers\` property.`)}_getLayerBySourceId(e){let t=this.utilityNetwork.getLayerIdBySourceId(e);return this._getLayerByLayerId(t)}_getLayerByLayerId(e){if(e==null)return;let{_layerByLayerId:t,layers:s}=this;if(t.get(e))return t.get(e);let r=s.find(i=>"layerId"in i&&i.layerId===e);return r&&t.set(e,r),r}async _loadDependencies(){let{layers:e,utilityNetwork:t}=this;if(!t)return;t.loaded||(this._state="loading",await t.load());let s=e.filter(r=>!r.loaded&&t.isUtilityLayer(r)).map(r=>r.load());s.length>0&&(this._state="loading",await Promise.allSettled(s)),this._state="ready"}render(){if(!this.utilityNetwork)return;let{_messages:e}=this,t=Array.from(this._sourceIdToFeatureCount.entries()).sort(this._compareByLayerTitle).map(this._renderLayerListItem);return l`<calcite-panel .loading=${this._state==="loading"}><calcite-list .label=${e.labels.traceResultElementsByLayer}>${t}</calcite-list></calcite-panel>`}};d("arcgis-utility-network-result-feature-list",o);export{o as ArcgisUtilityNetworkResultFeatureList};
