import{u as V}from"./useFormChange-B0pYJsvh.js";import{q as b,S as j,r as k}from"./app-DB4YCWeF.js";function z({isEdit:i=!1,getProperties:_,onChange:f=null,onSubmit:D=null,initialData:q={}}){var $;const{props:l}=b();let{page:t}=l;i&&(t.data=l[t==null?void 0:t.name]);let s={};for(const r of t==null?void 0:t.fields){const o=($=t==null?void 0:t.data)==null?void 0:$[r.name];s[r.name]=o??r.defaultValue??""}s={...s,...q};const m=j({...s,ref_url:l.location}),{data:n,setData:c,post:F,errors:h}=m,e=r=>{if(f)return f(r,n,c);const{name:o,value:a}=V(r,n);c(d=>({...d,[o]:a}))},B=r=>{var o,a,d,x,S;if(r==null||r.preventDefault(),D)return D(r,m);if(t!=null&&t.data){n._method="put";let u=(o=t==null?void 0:t.data)==null?void 0:o.id;return!u&&((a=t==null?void 0:t.data)!=null&&a.id_id)&&(u=(d=t==null?void 0:t.data)==null?void 0:d.id_id),!u&&((x=t==null?void 0:t.data)!=null&&x.id_en)&&(u=(S=t==null?void 0:t.data)==null?void 0:S.id_en),F(`${t==null?void 0:t.url}/${u}`)}return F(`${t==null?void 0:t.url}`)},v={data:n,errors:h,handleChange:e},M=k.useMemo(()=>_({...v,setData:c,props:l,isEdit:i}),[n,h,e,f,i,_]);return{form:m,properties:M,inputProps:v,handleChange:e,handleSubmit:B}}export{z as u};
