/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{a as u}from"./QUFMR3GW.js";import{a as f}from"./TLYY3J5P.js";import"./WGGFNK4Z.js";import"./EH5Y2TRK.js";import"./UANLRLKZ.js";import{u as m,y as l}from"./DVG3NA3H.js";import"./OAOQ5BXS.js";import{E as r,F as h,G as d,S as p,g as c,h as o,p as n}from"./PGOMURMZ.js";var g=c`:host([disabled]){cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-opacity-disabled)}:host([disabled]) *,:host([disabled]) ::slotted(*){pointer-events:none}:host{display:flex}.container{display:flex;inline-size:100%;flex-wrap:wrap;gap:.5rem}::slotted(calcite-chip){flex:none}:host([scale=s]) .container{gap:.25rem}:host([scale=l]) .container{gap:.75rem}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}.interaction-container{display:contents}:host([hidden]){display:none}[hidden]{display:none}`,a=class extends d{constructor(){super(),this.items=[],this.slotRef=r(),this.focusSetter=f()(this),this.interactiveContainer=u(this),this.disabled=!1,this.scale="m",this.selectedItems=[],this.selectionMode="none",this.calciteChipGroupSelect=n({cancelable:!1}),this.listen("calciteInternalChipKeyEvent",this.calciteInternalChipKeyEventListener),this.listen("calciteChipClose",this.calciteChipCloseListener),this.listen("calciteChipSelect",this.calciteChipSelectListener),this.listen("calciteInternalChipSelect",this.calciteInternalChipSelectListener),this.listen("calciteInternalSyncSelectedChips",this.calciteInternalSyncSelectedChips)}static{this.properties={disabled:[7,{},{reflect:!0,type:Boolean}],label:1,scale:[3,{},{reflect:!0}],selectedItems:[0,{},{attribute:!1}],selectionMode:[3,{},{reflect:!0}]}}static{this.styles=g}async setFocus(e){return this.focusSetter(()=>this.selectedItems[0]||this.items[0],e)}willUpdate(e){e.has("selectionMode")&&(this.hasUpdated||this.selectionMode!=="none")&&this.updateItems()}calciteInternalChipKeyEventListener(e){if(e.composedPath().includes(this.el)){let t={ArrowRight:"next",ArrowLeft:"previous",Home:"first",End:"last"}[e.detail.key];if(t){let i=this.items?.filter(I=>!I.disabled);l(i,e.detail.target,t,!0,!0,!0)}}e.stopPropagation()}calciteChipCloseListener(e){let s=e.target;this.items?.includes(s)&&(this.items?.indexOf(s)>0?l(this.items,s,"previous",!1,!1):this.items?.indexOf(s)===0?l(this.items,s,"next",!1,!1):l(this.items,s,"first",!1,!1)),this.items=this.items?.filter(t=>t!==s),e.stopPropagation()}calciteChipSelectListener(e){e.composedPath().includes(this.el)&&this.setSelectedItems(!0,e.target),e.stopPropagation()}calciteInternalChipSelectListener(e){e.composedPath().includes(this.el)&&this.setSelectedItems(!1,e.target),e.stopPropagation()}calciteInternalSyncSelectedChips(e){e.composedPath().includes(this.el)&&(this.updateSelectedItems(),this.selectionMode==="single"&&this.selectedItems.length>1&&this.setSelectedItems(!1,e.target)),e.stopPropagation()}updateItems(e){let s=this.slotRef.value?.assignedElements({flatten:!0}).filter(t=>t?.matches("calcite-chip"))||[];this.items=e?m(e):s,!(this.items?.length<1)&&(this.items?.forEach(t=>{t.interactive=!0,t.scale=this.scale,t.selectionMode=this.selectionMode,t.parentChipGroup=this.el}),this.setSelectedItems(!1))}updateSelectedItems(){this.selectedItems=this.items?.filter(e=>e.selected)}setSelectedItems(e,s){s&&this.items?.forEach(t=>{let i=s===t;switch(this.selectionMode){case"multiple":i&&(t.selected=!t.selected);break;case"single":t.selected=i?!t.selected:!1;break;case"single-persist":t.selected=!!i;break}}),this.updateSelectedItems(),e&&this.calciteChipGroupSelect.emit()}render(){let e=this.selectionMode==="none"||this.selectionMode==="multiple"?"group":"radiogroup",{disabled:s}=this;return this.interactiveContainer({disabled:s,children:o`<div .ariaLabel=${this.label} class="container" .role=${e}><slot @slotchange=${this.updateItems} ${h(this.slotRef)}></slot></div>`})}};p("calcite-chip-group",a);export{a as ChipGroup};
