import{r as t,h as e}from"./p-aee8b1df.js";const i=class{constructor(e){t(this,e),this.hack=0,this.addInput=t=>{const e=[...t,{id:window.BCE.generateId(),label:"",required:!1,type:"text"}];this.handler.set("input",e,{emit:!0,localize:!0}),setTimeout(()=>this.hack++,60)},this.editInput=(t,e,i,s)=>{const n=this.input.findIndex(e=>e.id===t),o=[...this.input],l=Object.assign(Object.assign({},this.input[n]),{[i]:s});o.splice(n,1,l),this.handler.set("input",o,{emit:!0,localize:!0}),e.stopPropagation()},this.removeInput=(t,e)=>{const i=t.filter(t=>t.id!==e);this.handler.set("input",i,{emit:!0,localize:!0}),setTimeout(()=>this.hack++,60)}}get input(){return this.handler.get("input",{localize:!0})}prop(t,e={}){return this.handler.prop(t,Object.assign({},e))}renderInputCreator(t,i){const s=this.editInput.bind(this,i.id);return e("div",{class:"input-creator",id:i.id,key:i.id},e("bce-select",{placeholder:"Type",type:"dropdown",value:i.type,onInput:t=>s(t,"type",t.target.value)},e("bce-option",{value:"date"},"Date"),e("bce-option",{value:"text"},"Text")),e("bce-input",{placeholder:"Label",value:i.label,onInput:t=>s(t,"label",t.target.value||"")}),e("label",null,this.t("me-required")),e("bce-switch",{value:i.required,onInput:t=>s(t,"required",t.target.value)}),e("bce-button",{design:"text",icon:"fas:trash",onClick:()=>this.removeInput(t,i.id)}))}render(){const t=this.prop("input",{default:()=>[],localize:!0}).value;return[t.map(e=>this.renderInputCreator(t,e)),e("bce-button",{design:"text",icon:"fas:plus",onClick:()=>this.addInput(t),"data-i":this.hack},this.t("add-item",{item:"Input"})),e("slot",null)]}static get style(){return":host{position:relative;display:block}:host .input-creator{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;margin:20px 0}:host .input-creator bce-input,:host .input-creator bce-select{margin:0}:host .input-creator bce-input{-ms-flex:1 1 auto;flex:1 1 auto}:host .input-creator label{margin:0 16px}:host .input-creator bce-switch{-ms-flex:0 0 auto;flex:0 0 auto;margin:0 16px 0 0}"}};export{i as bce_element_form_editor};