import{r as e,h as t,g as i}from"./p-aee8b1df.js";const r=class{constructor(t){e(this,t),this.value={},this.handleInput=e=>{const t=e.target;if(!t)return;const i=t.id,r=t.value||"",s=t.label||"";this.value=Object.assign(Object.assign({},this.value),{[i]:r,[s]:r}),this.el.dispatchEvent(new Event("input",{bubbles:!0}))}}async validate(e=!1){const t=this.el.shadowRoot.querySelectorAll("bce-input"),i=Array.from(t),r=await Promise.all(i.map(t=>t.validate(e)));return[].concat(...r)}isSelect(e){return"radio"===e.type}renderInput(e){return t("bce-input",{id:e.id,key:e.id,label:e.label,type:e.type,validation:e.required?"required":void 0,value:this.value[e.id]||"",onInput:this.handleInput})}renderSelect(e){return t("bce-select",{id:e.id,key:e.id,label:e.label,type:e.type,validation:e.required?"required":void 0,value:this.value[e.id]||"",onInput:this.handleInput},(e.options||[]).map((e,i)=>t("bce-option",{key:i,value:e},e)))}render(){return this.template.input.map(e=>this.isSelect(e)?this.renderSelect(e):this.renderInput(e))}get el(){return i(this)}static get style(){return":host{position:relative;display:block}"}};export{r as bce_element_form};