import{__assign as e,__awaiter as r,__generator as n,__spreadArrays as t}from"../../../../../node_modules/tslib/tslib.es6.js";import o,{useState as i}from"react";import l from"./FormGeneratorComponent/FormGeneratorStructure.js";import s from"./FormGeneratorComponent/FormGeneratorElement.js";import{FieldEntity as u}from"./FormGeneratorComponent/FormGeneratorEntities/Field.js";import{FormEntity as a}from"./FormGeneratorComponent/FormGeneratorEntities/Form.js";import{NumericValidatorEntity as m,EmailValidatorEntity as d,RequiredValidatorEntity as f}from"./FormGeneratorComponent/FormGeneratorEntities/Validator.js";import{Input as c}from"../../../../../node_modules/@chakra-ui/input/dist/esm/input.js";export default function(p){var v=p.bloc,F=p.setValue,E=p.register,j=v.properties.json,g=i(function(r){var n;if(null==r)return new a;var t=JSON.parse(r||"{}"),o=null===(n=t.fields)||void 0===n?void 0:n.map((function(r){return new u(e(e({},r),{validators:r.validators.map((function(e){switch(e.type){case"required":return new f(e);case"email":return new d(e);case"numeric":return new m(e)}return null}))}))}));return new a(e(e({},t),{fields:o}))}(j)),w=g[0],y=g[1],G=i(!1),J=G[0],C=G[1],h=i(JSON.stringify(w)),N=h[0],S=h[1],b=i(null),O=b[0],q=b[1],x=i(0),V=x[0],_=x[1],k=i(!1),A=k[0],B=k[1],R=function(e){F("properties.json",e.target.value)},z=function(o){return r(void 0,void 0,void 0,(function(){var r,i,l;return n(this,(function(n){if(""!==o.label&&""!==o.type){if(C(!1),null!==O)return(r=t(w.fields)).splice(V,0,o),i=new a(e(e({},w),{fields:t(r)})),q(null),y(i),S(JSON.stringify(i.toJson())),[2];l=new a(e(e({},w),{fields:t(w.fields,[o])})),q(null),y(l),S(JSON.stringify(l.toJson()))}else C(!0);return[2]}))}))},D=function(t){return r(void 0,void 0,void 0,(function(){var r,o;return n(this,(function(n){return r=-1,o=new a(e(e({},w),{fields:w.fields.filter((function(e,n){return e.id===t.id&&(r=n),e.id!==t.id}))})),_(r),y(o),S(JSON.stringify(o.toJson())),[2]}))}))};return o.createElement(o.Fragment,null,o.createElement("div",{className:"form-bloc-modal"},o.createElement(l,{editField:O,isEditing:null!==O,onAddField:z,onCancelEdit:function(){z(O),q(null),B(!1)},error:J,mandatoryField:A}),o.createElement(s,{form:w,onRemoveField:D,onEditField:function(e){D(e),q(e),e.validators.map((function(e){"required"===e.type?B(!0):B(!1)}))},isEditing:null!==O}),o.createElement(c,{type:"hidden",name:"properties.json",value:N,onChange:R,onBlur:R,ref:E}),o.createElement("style",{jsx:!0},"")))}
//# sourceMappingURL=DynamicFormSetting.js.map
