var __spreadArray=this&&this.__spreadArray||function(e,t,n){if(n||arguments.length===2)for(var r=0,a=t.length,i;r<a;r++){if(i||!(r in t)){if(!i)i=Array.prototype.slice.call(t,0,r);i[r]=t[r]}}return e.concat(i||Array.prototype.slice.call(t))};import{r as registerInstance,c as createEvent,h,H as Host}from"./index-b7735e0d.js";var dvnFieldInputSubFormCss="dvn-field-input-sub-form{display:block}dvn-field-input-sub-form .form-container{margin-top:calc(4 * var(--spacing-unit));position:relative}dvn-field-input-sub-form .form-container.separated{border:1px solid var(--color-border);padding:calc(4 * var(--spacing-unit));border-radius:var(--corner-radius)}dvn-field-input-sub-form .form-container .remove-input-button i,dvn-field-input-sub-form .form-container .add-input-button i{line-height:1rem}dvn-field-input-sub-form .form-container .remove-input-button{position:absolute;top:6px;left:-8px}dvn-field-input-sub-form doldurma-form{--form-min-height:0px}";var DvnFieldInputSubForm=function(){function e(e){var t=this;registerInstance(this,e);this.change=createEvent(this,"change",7);this.getParentValue=function(){return t.value||new Array(t.field.minCount).fill(undefined)}}e.prototype.componentWillLoad=function(){if(this.field.maxCount===1){return}this.subFormKeys=this.getParentValue().map((function(){return"".concat(Math.random())}))};e.prototype.render=function(){var e=this;var t=this,n=t.field,r=t.errors,a=t.subFormKeys,i=t.value;var o=r&&r.length>0;var u=o?r[0]:undefined;if(n.maxCount===1){var s=n.fields.map((function(e){return Object.assign(Object.assign({},e),{value:(i||{})[e.id]})}));return h(Host,null,h("div",{class:{"form-container":true,separated:n.separated}},h("doldurma-form",{fields:s,layout:n.layout,onChange:function(t){t.stopImmediatePropagation();e.change.emit(t.detail)}})),h("div",null,u))}var l=this.getParentValue();return h(Host,null,l.map((function(t,r){var i=t?n.fields.map((function(e){return Object.assign(Object.assign({},e),{value:t[e.id]})})):n.fields;return h("div",{key:a[r],class:{"form-container":true,separated:n.separated}},h("doldurma-form",{fields:i,layout:n.layout,onChange:function(t){t.stopImmediatePropagation();var n=__spreadArray([],l,true);n[r]=t.detail;e.change.emit(n)}}),l.length>n.minCount&&h("dvn-button",{class:"remove-input-button",shape:"circle",scale:"x-small",tint:"danger",leaned:true,onClick:function(t){t.stopImmediatePropagation();e.subFormKeys=a.filter((function(e,t){return t!==r}));e.change.emit(l.filter((function(e,t){return t!==r})))}},h("i",{class:"uil uil-minus"})))})),l.length<n.maxCount&&h("dvn-button",{class:"add-input-button",shape:"circle",view:"flat",scale:"small",leaned:true,onClick:function(t){t.stopImmediatePropagation();e.subFormKeys=__spreadArray(__spreadArray([],a,true),["".concat(Math.random())],false);e.change.emit(__spreadArray(__spreadArray([],l,true),[undefined],false))}},h("i",{class:"uil uil-plus"})),h("div",null,u))};return e}();DvnFieldInputSubForm.style=dvnFieldInputSubFormCss;export{DvnFieldInputSubForm as dvn_field_input_sub_form};