import{r as t,h as i,H as e,g as s}from"./p-aee8b1df.js";const n=class{constructor(i){t(this,i),this.handleFocus=()=>{},this.handleOption=t=>{if(!this.template)return;t.cancelBubble=!0;const i=parseInt(t.target.value,10);if(!isNaN(i)){if(this.value={index:i,text:this.template.options[i].text},this.template.other&&i===this.template.options.length-1){const t=this.el.shadowRoot.querySelector("bce-option bce-input");this.value.text=t.value,t.shadowRoot.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}))}}async validate(t=!1){const i=this.el.shadowRoot.querySelectorAll("bce-input, bce-select"),e=Array.from(i),s=await Promise.all(e.map(i=>i.validate(t)));return[].concat(...s)}renderOther(t,e){const s=this.value&&this.value.index===e;return i("bce-input",{placeholder:t.text,validation:s?"required":"",value:(s?this.value.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,e):t.text):null}render(){return this.template?i(e,{orientation:this.template.orientation},i("p",null,this.handler.t("question")),i("bce-select",{type:"radio",validation:this.template.required?"required":"",value:this.value?""+this.value.index:void 0,onInput:this.handleOption},this.handler.t("options").map((t,i)=>this.renderOption(t,i)))):null}get el(){return s(this)}static get style(){return":host p{font-weight:500;text-align:center}\@media screen and (min-width: 1024px){:host p{text-align:left}}:host bce-input{margin:0;padding:0 0 8px}:host([orientation=horizontal]) bce-option{display:-ms-inline-flexbox;display:inline-flex;margin:0 10px}"}};export{n as bce_element_radio};