import{__decorate as t}from"tslib";import{html as s}from"lit";import{queryAll as i,query as e,property as o,customElement as l}from"lit/decorators.js";import{s as n}from"./nile-button-toggle-group.css.esm.js";import{N as h}from"../nile-button-toggle/nile-button-toggle.esm.js";import{N as a}from"../internal/nile-element.esm.js";import"../nile-button-toggle/nile-button-toggle.css.esm.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let r=class extends a{constructor(){super(...arguments),this.disabled=!1,this.value="",this.multiple=!1,this.disableUserInput=!1,this.emptyDefault=!1}static get styles(){return[n]}firstUpdated(){if(this.defaultSlot.addEventListener("slotchange",(()=>this.updateTogglePositions())),this.addEventListener("nile-toggle-change",this.handleToggle),this.updateTogglePositions(),!this.value)if(this.multiple)this.value=[];else{const t=Array.from(this.querySelectorAll("nile-button-toggle")),s=t.find((t=>t.active&&!t.disabled));s?this.value=s.value:!t.length||this.emptyDefault||this.disabled?this.value="":this.value=t[0].value}this.setBtnState()}updated(t){super.updated(t),t.has("disabled")&&this.updateDisabledState(),t.has("multiple")&&(this.value||(this.value=this.multiple?[]:""),this.setBtnState()),t.has("value")&&this.setBtnState()}updateDisabledState(){this.defaultSlot.assignedNodes({flatten:!0}).filter((t=>t instanceof h)).forEach((t=>{t.disabled||(t.disabled=this.disabled)}))}updateTogglePositions(){const t=this.defaultSlot.assignedNodes({flatten:!0}).filter((t=>t instanceof h));t.forEach(((s,i)=>{s.initial=0===i,s.middle=i>0&&i<t.length-1,s.end=i===t.length-1}))}handleToggle(t){t.stopPropagation(),this.disabled||(this.multiple||t.detail.value!=this.value)&&(this.disableUserInput||(this.setValue(t.detail.value),this.emit("nile-change",{value:this.value})))}setValue(t){this.multiple&&t?this.value.includes(t)?this.value=this.value.filter((s=>s!=t)):this.value=[...this.value,t]:this.value=t,this.setBtnState()}setBtnState(){const t=Array.from(this.querySelectorAll("nile-button-toggle"));this.multiple?t.forEach((t=>{this.value.includes(t.value)?t.active=!0:t.active=!1})):t.forEach((t=>{t.value==this.value?t.active=!0:t.active=!1}))}render(){return s`<slot> </slot>`}};t([i("nile-button-toggle")],r.prototype,"toggles",void 0),t([e("slot:not([name])")],r.prototype,"defaultSlot",void 0),t([o({type:Boolean,reflect:!0})],r.prototype,"disabled",void 0),t([o()],r.prototype,"value",void 0),t([o({type:Boolean})],r.prototype,"multiple",void 0),t([o({type:Boolean})],r.prototype,"disableUserInput",void 0),t([o({type:Boolean})],r.prototype,"emptyDefault",void 0),r=t([l("nile-button-toggle-group")],r);export{r as N};
