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