import{r as t,c as e,g as i,h as n,d as s}from"./p-b3a13b6a.js";import{d as l}from"./p-3e4d9396.js";import{m as p}from"./p-b2f2fbb6.js";import{p as o}from"./p-df8bfe03.js";import{v as a}from"./p-4ed69de7.js";const r="pn-multiple-input .multiple-input-generated-row,pn-multiple-input .multiple-input-row{display:flex;gap:1rem}pn-multiple-input .multiple-input-generated-row pn-marketweb-input,pn-multiple-input .multiple-input-row pn-marketweb-input{width:100%}pn-multiple-input .multiple-input-slot{display:flex;gap:1rem;flex-direction:column;margin-top:1rem;margin-bottom:1rem}";const u=r;const h=class{constructor(i){t(this,i);this.allFormValues=e(this,"allFormValues",7);this.label=null;this.placeholder=null;this.addRowButtonText=null;this.rowData=[]}get hostElement(){return i(this)}pnSlotElement=null;_formValues=[];allFormValues;componentWillLoad(){const t=this.generateUniqueId();const e={id:t,input:""};this.rowData=[...this.rowData,e]}componentDidLoad(){this.addEventHandlers()}componentDidUpdate(){this.addEventHandlers()}addEventHandlers(){const t=this.pnSlotElement.querySelectorAll("pn-marketweb-input");t.forEach((t=>{t.addEventListener("keyup",l(this.handleInput.bind(this),500))}))}generateUniqueId(){return a()}deleteRow(t){if(t<0){return}this.rowData.splice(t,1);this.rowData=[...this.rowData];this.emitValues()}addRow(){const t={id:this.generateUniqueId(),input:""};this.rowData=[...this.rowData,t];this.emitValues()}handleInput(t){const e=t.target;const i=e.closest("pn-marketweb-input");if(!i){return}const n=i.id;const s=e.value;const l=this.rowData.findIndex((t=>t.id===n));if(l<0){return}this.rowData[l]={...this.rowData[l],input:s};this.emitValues()}emitValues(){this._formValues=[];const t=this.label?this.label:"InputField";this.rowData.forEach((e=>{const i={row:[]};if(e.input){const n={name:t,value:e.input};i.row.push(n)}if(i.row.length===1){this._formValues.push(i)}}));if(this._formValues.length===this.rowData.length){const t=JSON.stringify(this._formValues);this.allFormValues.emit(t)}else{this.allFormValues.emit("")}}render(){return n(s,{key:"c19a4c61c107632a3e97217c18ee4c2076ae077e"},n("div",{key:"71fb803627c006e137db1f6be32fb26ab144c876",ref:t=>this.pnSlotElement=t,class:"multiple-input-slot"},this.rowData?.map(((t,e)=>n("div",{class:"multiple-input-generated-row"},n("pn-marketweb-input",{label:this.label,type:"text",placeholder:this.placeholder,value:t.input,id:t.id}),e>0?n("pn-button",{arialabel:"Delete",icon:p,appearance:"warning",onClick:()=>{this.deleteRow(e)},index:e,id:t.id},"Delete"):null)))),n("dvi",{key:"dc7c599822a8e8c39064ecc2ff76cea767ef757f",class:"multiple-input-row"},n("pn-button",{key:"9289b646075f389d935f8a8be3f2490d0e102005",tooltip:this.addRowButtonText?this.addRowButtonText:null,"left-icon":"true",arialabel:"Add",icon:o,appearance:"light",variant:"borderless",class:"connected-dropdown__button-right",onClick:()=>{this.addRow()}},this.addRowButtonText)))}};h.style=u;export{h as pn_multiple_input};
//# sourceMappingURL=p-8a76d782.entry.js.map