import{r as t,h as e,H as i,g as s}from"./p-3ba9c73c.js";const n=class{constructor(e){t(this,e),this.handleOption=t=>{if(!this.template)return;t.cancelBubble=!0;const e=t.target.value||[],i=this.el.querySelector("bce-option bce-input");this.value=e.map(t=>{const e=parseInt(t,10);return{index:e,text:i&&e===this.template.options.length-1?i.value:this.template.options[e].text}}),this.el.dispatchEvent(new Event("input",{bubbles:!0}))},this.handleInput=t=>{t.cancelBubble=!0;const e=Array.from(this.el.querySelectorAll("bce-option")||[]),i=e[e.length-1];if(!i.checked)return;const s=t.target;this.value=[...this.value.slice(0,-1),{index:parseInt(i.value,10),text:s.value}],this.el.dispatchEvent(new Event("input",{bubbles:!0}))}}renderOther(t,i){const s=this.value&&this.value[this.value.length-1];return e("bce-input",{placeholder:t.text,value:(s&&s.index===i?s.text:"")||"",onInput:this.handleInput})}renderOption(t,i){return this.template?e("bce-option",{value:""+i},this.template.other&&i===this.template.options.length-1?this.renderOther(t,i):t.text):null}render(){return this.template?e(i,{orientation:this.template.orientation},e("p",null,this.template.question),e("bce-input",{type:"checkbox",validation:this.template.required?"required":"",value:this.value&&this.value.map(t=>""+t.index),onInput:this.handleOption},this.template.options.map((t,e)=>this.renderOption(t,e)))):null}get el(){return s(this)}static get style(){return"bce-element-checkbox p{font-weight:500;text-align:center}\@media screen and (min-width:1024px){bce-element-checkbox p{text-align:left}}bce-element-checkbox bce-option[type=checkbox][checked] bce-input[focus] input{border-color:var(--bce-color-n)}bce-element-checkbox bce-option[type=checkbox][checked] bce-input input{background-color:var(--bce-color-light-l);border:1px solid var(--bce-color-light-d)}bce-element-checkbox bce-option[type=checkbox] bce-input{margin:0;width:auto;min-width:200px}bce-element-checkbox bce-option[type=checkbox] bce-input input{margin:0;min-width:200px;border-radius:4px}"}};export{n as bce_element_checkbox};