/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import c from"./N6IQW2WT.js";import b from"./C2LXNVZ5.js";import{a as u}from"./6S75SIVV.js";import"./5IZMQFRP.js";import"./FOQPGXXA.js";import{b as m}from"./ABSRNM72.js";import{H as p,h as y,i as a,r as o,u as d}from"./5CQPQ7AE.js";import"./3QPJ2JCA.js";export default $arcgis.t(([n,g,,{a:f,c:L,e:w}])=>{async function I(h,e){let{style:s="decimal",places:t=2}=e||{},i=n.convertNumberFormatToIntlOptions({places:t,digitSeparator:!0});return i.style=s,n.formatNumber(h,i)}var x=y`@layer{
/** @license
 * Copyright 2025 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

:host {
  display: block;
}

.notice-msg {
  width: calc(100% - 20px);
  padding: 10px;
}

.layer-name {
  font-weight: 500;
  word-break: break-word;
}

.feature-count {
  padding: 0 10px;
}
}`,l=class extends p{constructor(){super(),this.layers=[],this.showFeatureCount=!0,this.showNextIcon=!1,this.applyLayerViewFilter=!1,this.filterByMapExtent=!1,this._noLayersToDisplay=!1,this._mapLayerIds=[],this._isLoading=!1,this._translations=u({name:"layer-list",blocking:!0}),this.layerSelect=o(),this.layersListLoaded=o(),this.listenOn(window,"selectedLanguageUpdated",this.selectedLanguageUpdated)}static{this.properties={mapView:[0,{},{attribute:!1}],layers:[0,{},{attribute:!1}],showFeatureCount:[5,{},{type:Boolean}],showNextIcon:[5,{},{type:Boolean}],applyLayerViewFilter:[5,{},{type:Boolean}],filterByMapExtent:[5,{},{type:Boolean}],_noLayersToDisplay:[16,{},{state:!0}],_mapLayerIds:[16,{},{state:!0}],_isLoading:[16,{},{state:!0}],_translations:[16,{},{state:!0}]}}static{this.styles=x}static{this.shadowRootOptions=d}willUpdate(e){e.has("filterByMapExtent")&&this.hasUpdated&&this.filterByMapExtentWatchHandler(this.filterByMapExtent)}filterByMapExtentWatchHandler(e){e?this.initializeMapExtentFilter():this._filterByMapExtentHandle&&this._filterByMapExtentHandle.remove()}async refresh(){await this.setLayers()}async selectedLanguageUpdated(e){await this.setLayers()}async load(){this.filterByMapExtent&&this.initializeMapExtentFilter()}async loaded(){await this.setLayers()}render(){return a`${this._isLoading&&a`<calcite-loader label scale=m></calcite-loader>`||""}${!this._isLoading&&this.mapView&&this._noLayersToDisplay&&a`<calcite-notice class="notice-msg" icon=layers-reference kind=danger open><div slot=title>${this._translations.error}</div><div slot=message>${this._translations.noLayerToDisplayErrorMsg}</div></calcite-notice>`||""}${!this._isLoading&&this.mapView&&a`<calcite-list label selection-appearance=border selection-mode=none>${this.filterByMapExtent&&this._mapLayerIds.length>0&&this.getExtentNotice()||""}${this.renderLayerList()}</calcite-list>`||""}`}initializeMapExtentFilter(){this._filterByMapExtentHandle=g.when(()=>this.mapView?.stationary,()=>{this.setLayers()},{initial:!0})}async setLayers(){this.mapView&&(this._isLoading=!0,await this.initLayerHash(),this._isLoading=!1)}async initLayerHash(){let e=[];if(this.mapView){this._layerItemsHash=await f(this.mapView,!0);let s=await w(this.mapView);for(let t of s)if(t?.type==="feature"&&this.showFeatureCount){let i=t.createQuery();if(t?.definitionExpression&&(i.where=i.where+" AND "+t.definitionExpression),this.applyLayerViewFilter){let r=await L(this.mapView,t.id);r?.filter?.where&&(i.where=i.where?i.where+" AND "+r.filter.where:r.filter.where)}i.geometry=this.filterByMapExtent?this.mapView.extent:null;let c=t.queryFeatureCount(i);e.push(c),c.then(async r=>{let _=Number.isNaN(r)?"":await I(r,{places:0,style:"decimal"});this._layerItemsHash&&(this._layerItemsHash[t.id].formattedFeatureCount=_)})}await Promise.all(e).then(()=>{let t=this._layerItemsHash&&this.getLayersToBeShownInList(this._layerItemsHash);this._mapLayerIds=t?.reverse()||[],this.handleNoLayersToDisplay()},()=>{this._mapLayerIds=[],this.handleNoLayersToDisplay()})}}handleNoLayersToDisplay(){this._noLayersToDisplay=!(this._mapLayerIds.length>0),this.layersListLoaded.emit(this._mapLayerIds)}getLayersToBeShownInList(e){let s=this.layers?.length>0?this.layers:[];return Object.keys(e).reduce((t,i)=>(s.indexOf(i)>-1&&t.push(i),t),[])}renderLayerList(){return this._mapLayerIds.length>0?this._mapLayerIds.reduce((e,s)=>{if(this._layerItemsHash&&this._layerItemsHash[s]){let t=this.getLayerListItem(s);t&&e.push(t)}return e},[]):void 0}getLayerListItem(e){let s=this._layerItemsHash&&this._layerItemsHash[e].name,t=this._layerItemsHash&&this._layerItemsHash[e].formattedFeatureCount;return a`<calcite-list-item @calciteListItemSelect=${()=>{this.onLayerItemSelected(e)}}><div class="layer-name" slot=content-start>${s}</div>${this.showFeatureCount&&t!==void 0&&t!==""&&a`<div class="feature-count" slot=content-end>${`(${t})`}</div>`||""}${this.showNextIcon&&a`<calcite-icon flip-rtl icon=chevron-right scale=s slot=content-end></calcite-icon>`||""}</calcite-list-item>`}getExtentNotice(){return a`<calcite-notice class="notice-msg" icon=extent-filter kind=brand open scale=s><div slot=message>${this._translations.extentFilterMsg}</div></calcite-notice>`}onLayerItemSelected(e){this._layerItemsHash&&this.layerSelect.emit({layerId:e,layerName:this._layerItemsHash[e]?.name})}};m("layer-list",l);return l},"intl","core/reactiveUtils",b,c)