import{r as s,c as t,g as i,h as e,H as a}from"./p-21516f8c.js";import{f as h}from"./p-36e2fdf2.js";const r="lu-radio-group{display:flex;flex-flow:column}lu-radio-group.direction-across{margin-left:0;margin-right:5px;flex-flow:row}";const l=class{constructor(i){s(this,i);this.luBlur=t(this,"luBlur",7);this.luChange=t(this,"luChange",7);this.inputId=`lu-rg-${o++}`;this.isResetting=false;this.ariaLabeledByAddition="";this.allowEmptySelection=false;this.direction="down";this.hasFormGroup=false;this.useId=this.inputId+"-wrapper";this.name=this.inputId;this.required=false;this.valid=false;this.invalid=false;this.mutationCallback=(s,t)=>{s.forEach((s=>{if(s.type==="childList"){for(let t=0;t<s.addedNodes.length;t++){const i=h(s.addedNodes[t],"lu-radio");if(i)i.forEach(this.handleNewRadio)}for(let t=0;t<s.removedNodes.length;t++){const i=h(s.removedNodes[t],"lu-radio");if(i)i.forEach(this.radioDisconnected)}}if(s.type==="attributes"){if(s.attributeName.toLowerCase()==="data-is-radio-checked"){this.updateRadios(s.target)}if(s.attributeName.toLowerCase()==="has-focus"){let s=true;this.getRadios().forEach((t=>{const i=t.getAttribute("has-focus");if(i||i===""){s=false}}));if(s){this.luBlur.emit()}}}}))};this.handleNewRadio=s=>{s.name=this.name;s.labeledById=this.inputId;this.updateRadios()};this.radioDisconnected=s=>{this.updateRadios()};this.getRadios=()=>Array.from(this.el.querySelectorAll("lu-radio"))}valueChanged(s){this.luChange.emit({value:s,isResetting:this.isResetting});this.isResetting=false}connectedCallback(){this.updateRadios();const s=this.el;this.mutationO=new MutationObserver(this.mutationCallback);this.mutationO.observe(s,{childList:true,subtree:true,attributes:true,attributeFilter:["data-is-radio-checked","has-focus"]})}disconnectedCallback(){this.mutationO.disconnect();this.mutationO=undefined}updateRadios(s){const t=this.getRadios();let i=false;for(const e of t){e.canDeselect=this.allowEmptySelection;if(s){if(e===s&&s.checked){this.value=s.value;i=true}else if(s.checked){e.checked=false}else if(e.checked){i=true}}else{if(e.checked&&!i){i=true;this.value=e.value}else{e.checked=false}}}if(!i){this.value=null}}async setFocus(){if(this.el){const s=this.el.querySelectorAll("lu-radio");if(s&&s[0]){s[0].focus()}}}async updateValue(s){this.isResetting=true;this.getRadios().forEach((t=>{if(JSON.stringify(t.value)===JSON.stringify(s)){t.checked=true}}))}hostData(){return Object.assign(Object.assign({class:{"is-radio-group":true,"direction-across":this.direction==="across"},role:"radiogroup"},(this.hasFormGroup||this.ariaLabeledByAddition&&this.ariaLabeledByAddition.length>0)&&{"aria-labelledby":`${this.ariaLabeledByAddition} `+(this.hasFormGroup?this.inputId+"-label":"")}),{id:this.useId,"is-valid":this.valid,"is-invalid":this.invalid})}get el(){return i(this)}static get watchers(){return{value:["valueChanged"]}}render(){return e(a,this.hostData())}};let o=0;l.style=r;export{l as lu_radio_group};
//# sourceMappingURL=p-dee8a558.entry.js.map