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