/* COPYRIGHT Esri - https://js.arcgis.com/1.2/LICENSE.txt */
import{a as v}from"./YOH3QK7R.js";import{b as L}from"./77CU4WA2.js";import e from"./N6IQW2WT.js";import a from"./C2LXNVZ5.js";import{a as g}from"./6S75SIVV.js";import"./5IZMQFRP.js";import"./FOQPGXXA.js";import{b as _}from"./ABSRNM72.js";import{F as o,G as d,H as f,J as p,K as c,h as b,i,l,r,u}from"./5CQPQ7AE.js";import"./3QPJ2JCA.js";export default $arcgis.t(([,{a:w,b:I,d:y}])=>{var O=b`@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;
}

.map-layer-picker-container {
  width: 100%;
  align-items: center;
}

.map-layer-picker {
  position: relative;
  width: 100%;
  display: inline-block;
}

.padding-bottom-1 {
  padding-bottom: 1rem;
}

.layer-picker-dropdown {
  height: 100%;
  width: 100%;
}

.max-width-350 {
  max-width: 350px;
}

.height-100 {
  height: 100%;
}

.disabled {
  cursor: default !important;
  user-select: none;
  opacity: var(--calcite-opacity-disabled);
  pointer-events: none;
}

.no-bottom-margin {
  --calcite-label-margin-bottom: 0px;
}

.layer-picker-label-container {
  align-items: center;
  display: inline-flex;
  height: 100%;
  padding-inline-start: 1rem;
  padding-inline-end: 1rem;
}

.padding-start-1 {
  padding-inline-start: 1rem;
}

.cursor-default {
  cursor: default;
}

.popover-list {
  overflow: auto;
  width: 250px;
}
}`,m=class extends f{constructor(){super(),this.appearance="transparent",this.configLayerOrderDefined=!1,this.defaultLayerId="",this.disabled=!1,this.display="inline-block",this.enabledLayerIds=[],this.isMobile=!1,this.showOnlyUpdatableLayers=!1,this.selectedIds=[],this.scale="m",this.showTables=!1,this.showTablesDisabled=!1,this.showSingleLayerAsLabel=!1,this.type="select",this.showLayersListInPopover=!1,this.referenceElement="",this.force=!1,this._hasMultipleLayers=!0,this._hasValidLayers=!0,this._isDropdownOpen=!1,this.ids=[],this.selectedName="",this._translations=g({name:"map-layer-picker",blocking:!0}),this.defaultLayerHonored=!1,this._layerSelectElement=o(),this._layerComboboxElement=o(),this._pnContextConsumer=L({context:v,subscribe:!0}),this._skipEditCheck=!1,this._popover=o(),this.beforeLayerSelectionChange=r(),this.idsFound=r(),this.noLayersFound=r(),this.layerSelectionChange=r(),this.listenOn(window,"mapChanged",this.mapChanged)}static{this.properties={appearance:1,configLayerOrderDefined:[5,{},{type:Boolean}],defaultLayerId:1,disabled:[5,{},{type:Boolean}],display:1,enabledLayerIds:[0,{},{attribute:!1}],height:[9,{},{type:Number}],isMobile:[5,{},{type:Boolean}],mapView:[0,{},{attribute:!1}],showOnlyUpdatableLayers:[5,{},{type:Boolean}],placeholderIcon:1,selectedIds:[0,{},{attribute:!1}],scale:1,showTables:[5,{},{type:Boolean}],showTablesDisabled:[5,{},{type:Boolean}],showSingleLayerAsLabel:[5,{},{type:Boolean}],type:1,showLayersListInPopover:[5,{},{type:Boolean}],referenceElement:1,force:[16,{},{state:!0}],_hasMultipleLayers:[16,{},{state:!0}],_hasValidLayers:[16,{},{state:!0}],_isDropdownOpen:[16,{},{state:!0}],ids:[16,{},{state:!0}],selectedName:[16,{},{state:!0}],_translations:[16,{},{state:!0}]}}static{this.styles=O}static{this.shadowRootOptions=u}willUpdate(e){e.has("mapView")&&this.hasUpdated&&this.mapViewWatchHandler(),e.has("type")&&(this._layerElement=this.type==="select"?this._layerSelectElement:this._layerComboboxElement),e.has("selectedIds")&&this.hasUpdated&&this.mapView&&(async()=>{let t=await y(this.mapView,this.selectedIds[0]);this.selectedName=t?.title??""})(),e.has("enabledLayerIds")&&this.hasUpdated&&this.enabledLayerIdsWatchHandler()}async enabledLayerIdsWatchHandler(){let e=this.selectedIds.length>0&&!this.enabledLayerIds.includes(this.selectedIds[0]),t=this.enabledLayerIds.some(a=>!this.ids.includes(a)),s=this.ids.toString()!==this.enabledLayerIds.toString();e?this.mapViewWatchHandler():(t||s)&&this._setLayers(),this._hasMultipleLayers=this.enabledLayerIds.length>1}async mapViewWatchHandler(){if(await this._setLayers(),this.ids?.length>0){this._hasValidLayers=!0,this._hasMultipleLayers=this.ids.length>1;let e=this.ids[0];this.defaultLayerId&&!this.defaultLayerHonored&&(e=this.defaultLayerId),await this._setSelectedLayer(e)}else this.mapView&&(this._hasValidLayers=!1,this.noLayersFound.emit())}async setLayerById(e,t=!1){this._skipEditCheck=t,!t||t&&e!==this.selectedIds[0]?this._setSelectedLayer(e):t&&e===this.selectedIds[0]&&(this.force=!0,setTimeout(()=>{this.force=!1},10)),this._skipEditCheck=!1}async setLayerByIds(e,t=!1){this._skipEditCheck=t,this._layerSelectionChange(e),this._skipEditCheck=!1}async updateLayer(){await this._setSelectedLayer(this.ids[0])}async mapChanged(e){e.detail.isValid||(this._hasValidLayers=!1,this.noLayersFound.emit())}async load(){await this._setLayers(),this.ids?.length>0?(this._hasValidLayers=!0,this._hasMultipleLayers=this.ids.length>1,this.defaultLayerId||await this._setSelectedLayer(this.ids[0])):this.mapView&&(this._hasValidLayers=!1,this.noLayersFound.emit())}render(){let e="map-layer-picker",t=this.height&&this.height>0&&!this.showLayersListInPopover?{height:`${this.height.toString()}px`}:{};return t={...t,display:this.display},i`<div class="map-layer-picker-container" style=${c(t)}><div class="map-layer-picker" style=${c(t)}>${this._hasValidLayers?!this._hasMultipleLayers&&this.showSingleLayerAsLabel?this._getSingleLayerPlaceholder():this.type==="combobox"?this._getCombobox(e):this.type==="select"?this._getSelect(e):this.showLayersListInPopover?this._getMapLayerPopOver():this._getDropdown(e):this._getInvalidPlaceholder()}</div></div>`}loaded(){if(this.ids?.length>0||this.selectedIds?.length===1){let e=this.selectedIds.length===1?this.selectedIds[0]:this.ids[0];this.type==="select"?this._layerElement.value&&(this._layerElement.value.value=e):this.type==="dropdown"&&(this.selectedName=this._layerNameHash&&Object.keys(this._layerNameHash).indexOf(e)>-1?this._layerNameHash[e].name:this._tableNameHash&&Object.keys(this._tableNameHash).indexOf(e)>-1?this._tableNameHash[e].name:"")}this._popover.value?.addEventListener("calcitePopoverOpen",()=>{this.el.querySelector("calcite-dropdown-item[selected]")?.setFocus()})}_getMapLayerPopOver(){let e=this.height&&this.height>0?{"max-height":`${this.height.toString()}px`}:{};return i`<calcite-popover auto-close focus-trap-disabled .label=${this.referenceElement} placement=left .referenceElement=${this.referenceElement} scale=s ${d(this._popover)}><div class=popover-list style=${c(e)}>${this._getMapLayerOptions()}</div></calcite-popover>`}_getInvalidPlaceholder(){return i`<div><calcite-notice class="height-100" icon=exclamation-mark-triangle id=no-valid-layers kind=danger open><div slot=message>${this._translations.noLayersFound}</div></calcite-notice><calcite-tooltip .label=${this._translations.enableEditUpdate} placement=bottom reference-element=no-valid-layers><span>${this._translations.enableEditUpdate}</span></calcite-tooltip></div>`}_getSingleLayerPlaceholder(){let e=this._getItemTypeIcon();return i`<div class="layer-picker-label-container cursor-default"><calcite-icon .icon=${e} scale=s></calcite-icon><calcite-label class="no-bottom-margin padding-start-1">${this.selectedName}</calcite-label></div>`}_getSelect(e){return i`<calcite-select .disabled=${this.disabled} id=${e??l} label @calciteSelectChange=${()=>this._layerSelectionChange()} .scale=${this.scale} ${d(this._layerElement)}>${this._getMapLayerOptions()}</calcite-select>`}_getCombobox(e){return i`<calcite-combobox clear-disabled id=${e??l} label @calciteComboboxChange=${()=>this._layerSelectionChange()} .placeholderIcon=${this.placeholderIcon} .scale=${this.scale} selection-mode=single ${d(this._layerElement)}>${this._getMapLayerOptions()}</calcite-combobox>`}_getDropdown(e){return i`<calcite-dropdown class="layer-picker-dropdown" @calciteDropdownBeforeClose=${()=>this._isDropdownOpen=!1} @calciteDropdownBeforeOpen=${()=>this._isDropdownOpen=!0}>${this.isMobile?this._getDropdownButton():this._getActionDropdownButton(e)}<calcite-dropdown-group selection-mode=single>${this._getMapLayerOptions()}</calcite-dropdown-group></calcite-dropdown>`}_getActionDropdownButton(e){return i`<calcite-action appearance=solid id=${e??l} slot=trigger text>${this._getDropdownButton()}</calcite-action>`}_getDropdownButton(){let e=this._getItemTypeIcon(),t=this.isMobile?"":"max-width-350",s=this.isMobile?"trigger":"",a=this._isDropdownOpen?"chevron-up":"chevron-down";return i`<calcite-button alignment=icon-end-space-between .appearance=${this.appearance} class=${p(t)} .iconEnd=${a} .iconStart=${e} kind=neutral slot=${s??l} width=full><div>${this.selectedName}</div></calcite-button>`}_getItemTypeIcon(){let e=this.selectedIds.length>0&&this._layerNameHash,t=e?this.selectedIds[0]:void 0;return e?Object.keys(this._layerNameHash).indexOf(t)>-1?"layers":"table":"layers"}_getMapLayerOptions(){return this.ids.reduce((e,t)=>(this._validLayer(t)?e.push(this._getItem(t,"layer")):this._validTable(t)&&e.push(this._getItem(t,"table")),e),[])}_getItem(e,t){let s=t==="layer"&&this._layerNameHash?this._layerNameHash[e]:this._tableNameHash?this._tableNameHash[e]:void 0,a=this.showOnlyUpdatableLayers?s&&!s.supportsUpdate:!1,n=s?.name||"",h=this.selectedIds.indexOf(e)>-1;return this.type==="combobox"?i`<calcite-combobox-item .disabled=${a} .heading=${n} .selected=${h} .value=${e}></calcite-combobox-item>`:this.type==="select"?i`<calcite-option .disabled=${a} .label=${n} .selected=${h} .value=${e}></calcite-option>`:this.force&&h||!this.force?i`<calcite-dropdown-group class=${p(a?"disabled":"")} id=${n??l} .selectionMode=${a?"none":"single"}><calcite-dropdown-item .disabled=${!!(t==="table"&&this.showTablesDisabled)} .iconStart=${t} @click=${a?void 0:()=>void this._setSelectedLayer(e)} .selected=${h}>${n}</calcite-dropdown-item></calcite-dropdown-group>`:null}async _setSelectedLayer(e){if(e!==this.selectedIds[0]){let t;if(this.defaultLayerId&&!this.defaultLayerHonored&&(t=this._getLayerFromHash(this.defaultLayerId),this.defaultLayerHonored=t!==void 0,e=this.defaultLayerHonored?this.defaultLayerId:e),t=t||this._getLayerFromHash(e),!this._skipEditCheck&&this.beforeLayerSelectionChange.emit({currentId:this.selectedIds[0],newId:e,ref:this.el}).defaultPrevented)return;this.selectedName=t?.name,this.selectedIds=[e],this._popover.value&&(this._popover.value.open=!1),this.layerSelectionChange.emit(this.selectedIds)}else{let t=this.mapView&&await y(this.mapView,this.selectedIds[0]);this.selectedName=t?.title||""}}_getLayerFromHash(e){return this._layerNameHash&&Object.keys(this._layerNameHash).indexOf(e)>-1?this._layerNameHash[e]:this._tableNameHash&&Object.keys(this._tableNameHash).indexOf(e)>-1?this._tableNameHash[e]:void 0}async _setLayers(){if(this.mapView){await this._initLayerTableHash();let e=[];this._layerNameHash&&(e=this.showOnlyUpdatableLayers?this._getEditableIds(this._layerNameHash):Object.keys(this._layerNameHash));let t=[];if(this._tableNameHash&&(t=this.showTables?this.showOnlyUpdatableLayers?this._getEditableIds(this._tableNameHash):Object.keys(this._tableNameHash):[]),this.configLayerOrderDefined){let s=[...e.reverse(),...t.reverse()];this.ids=this.enabledLayerIds.length>0?this.enabledLayerIds.filter(a=>s.includes(a)):s}else this.ids=[...e.reverse().filter(s=>this.enabledLayerIds?.length>0?this.enabledLayerIds.indexOf(s)>-1:!0),...t.reverse().filter(s=>this.enabledLayerIds?.length>0?this.enabledLayerIds.indexOf(s)>-1:!0)];this.idsFound.emit(this.ids)}}_getEditableIds(e){return Object.keys(e).filter(t=>e[t].supportsUpdate)}async _initLayerTableHash(){this._layerNameHash=this.mapView&&await w(this.mapView,this.showOnlyUpdatableLayers),this._tableNameHash=this.showTables&&this.mapView?await I(this.mapView,this.showOnlyUpdatableLayers):{}}_validLayer(e){let t=this._pnContextConsumer.value,s=this._layerNameHash&&this._layerNameHash[e]?.name;return s!==void 0&&Object.keys(t?.managedLayers||[]).indexOf(s)<0&&(this.enabledLayerIds?.length>0?this.enabledLayerIds.indexOf(e)>-1:!0)}_validTable(e){let t=this._pnContextConsumer.value,s=this._tableNameHash&&this._tableNameHash[e]?.name,a=s&&this.showTables;return a?(t?.managedTables||[]).indexOf(s)<0&&(this.enabledLayerIds?.length>0?this.enabledLayerIds.indexOf(e)>-1:!0):a!==void 0}_layerSelectionChange(e){if(this._layerElement.value){let t=e||(Array.isArray(this._layerElement.value.value)?this._layerElement.value.value:[this._layerElement.value.value]);if(JSON.stringify(t)!==JSON.stringify([""])){if(!this._skipEditCheck&&this.beforeLayerSelectionChange.emit({currentIds:this.selectedIds,newIds:t,ref:this.el}).defaultPrevented)return;this.selectedIds=t,this.layerSelectionChange.emit(this.selectedIds)}}}};_("map-layer-picker",m);return m},a,e)