import{r as s,c as t,h as i,H as h,g as e}from"./p-21516f8c.js";import{f as c}from"./p-36e2fdf2.js";const l="lu-checkbox-group{display:flex;flex-flow:column}lu-checkbox-group.direction-across{margin:0 5px 0 0;flex-flow:row}";const a=class{constructor(i){s(this,i);this.luBlur=t(this,"luBlur",7);this.luChange=t(this,"luChange",7);this.inputId=`lu-cg-${o++}`;this.isResetting=false;this.componentLoaded=false;this.ariaLabeledByAddition="";this.direction="down";this.useId=this.inputId+"-wrapper";this.name=this.inputId;this.required=false;this.valid=false;this.invalid=false;this.hasFormGroup=false;this.mutationCallback=(s,t)=>{s.forEach((s=>{if(s.type==="childList"){for(let t=0;t<s.addedNodes.length;t++){const i=c(s.addedNodes[t],"lu-checkbox");if(i)i.forEach(this.handleNewCheckbox)}for(let t=0;t<s.removedNodes.length;t++){const i=c(s.removedNodes[t],"lu-checkbox");if(i)i.forEach(this.checkboxRemoved)}}if(s.type==="attributes"){if(s.attributeName.toLowerCase()==="data-is-checked"){this.valueChanged()}if(s.attributeName.toLowerCase()==="has-focus"){let s=true;this.getCheckboxes().forEach((t=>{const i=t.getAttribute("has-focus");if(i||i===""){s=false}}));if(s){this.luBlur.emit()}}}}))};this.handleNewCheckbox=s=>{s.name=this.name;s.labeledById=this.inputId;this.value=this.getValues(this.getCheckboxes())};this.checkboxRemoved=s=>{this.valueChanged()};this.getCheckboxes=()=>Array.from(this.el.querySelectorAll("lu-checkbox"));this.valueChanged=()=>{this.value=this.getValues(this.getCheckboxes());this.luChange.emit({value:this.value,isResetting:this.isResetting})}}connectedCallback(){this.value=this.getValues(this.getCheckboxes());const s=this.el;this.mutationO=new MutationObserver(this.mutationCallback);this.mutationO.observe(s,{childList:true,subtree:true,attributes:true,attributeFilter:["data-is-checked","has-focus"]})}disconnectedCallback(){this.mutationO.disconnect();this.mutationO=undefined}async setFocus(){if(this.el){const s=this.el.querySelectorAll("lu-checkbox");if(s&&s[0]){s[0].focus()}}}getValues(s){return s.map((s=>({checked:s.checked,value:s.value,name:s.name})))}async updateValue(s){this.isResetting=true;s.forEach((s=>{const t=this.getCheckboxes().filter((t=>t.name===s.name))[0];if(t){t.checked=s.checked}}));setTimeout((()=>{this.isResetting=false}),20)}render(){return i(h,Object.assign({class:{"is-checkbox-group":true,"direction-across":this.direction==="across"},role:"group"},(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}),i("slot",null))}get el(){return e(this)}};let o=0;a.style=l;export{a as lu_checkbox_group};
//# sourceMappingURL=p-dbfb21e0.entry.js.map