import{K as k,r as d,b2 as A,h as H,j as i,ah as K,o as Y,M as q,a2 as D,b0 as p,b1 as u,m as l,Y as t}from"./index-e47c07e2.js";import{D as J,r as Q}from"./DatosDom-c731b021.js";import"./DialogContentText-bbf9f64d.js";const ro=({id:g})=>{const I=g||0,b=k(),f=a=>{P(a)};d.useEffect(()=>{(async()=>{try{const e=await D.post(`${p}/${u}/rest/mensajesPaperless/creaSession`,{iprid:s});await l.getData(parseInt(s),["sol","soldom","soldompar","solctt","solcrd"]).then(o=>{l.isTruthy(o.soldompar)&&(t.error("Domicilio ya cargado"),c(0))}).catch(o=>{t.error("Error al recuperar datos de solicitud"),console.error(o)})}catch(e){t.error("Error al actualizar domicilio"),console.error(e)}})()},[]);const P=a=>{v();const{CllId:e,DomCP:o,DomPuerta:$,LocId:V,PrvId:F,DomLat:N,DomLng:U,PartId:n,DomGoogleDet:m}=a;r("PrvId",F),r("DomCP",(o==null?void 0:o.toString())??""),r("LocId",V),r("CllId",e.toString()),r("DomPuerta",$),r("DomLat",N),r("DomLng",U),n!==void 0&&r("PartId",n),o!==void 0&&r("DomCP",o),m!==void 0&&r("DomGoogleDet",m)},{iprid:s}=A(),[h,c]=d.useState(1),{control:L,setValue:r,reset:v,handleSubmit:y,formState:C,watch:E,resetField:S,getValues:O}=H({defaultValues:{DomDet:"",PrvId:"",LocId:"",PartId:"",CllId:"",BarId:"",DomPuerta:"",DomCP:"",DomPiso:"",DomDepto:"",DomLat:"",DomLng:"",DomGoogleDet:"",DomObs:""}}),[j,w,x,G,M,z,B,R,T]=E(["DomLat","DomLng","PrvId","LocId","CllId","BarId","PartId","DomObs","DomPuerta"]);return i(K,{children:Y("form",{hidden:h!==1,onSubmit:y(async a=>{console.log(a);const e=await Q.guardar("Dom",{data:[{...a,DomObs:l.isTruthy(a.DomObs)?a.DomObs:"null",DomTip:"PAR"}],iprId:Number.parseInt(s===void 0?"":s)});e.success?(t.success("Domicilio guardadfo con exito."),await D.post(`${p}/${u}/rest/mensajesPaperless/actualizaProc`,{iprid:s}).then(o=>{c(0),b("/carga-dom-success",{replace:!0})}).catch(o=>{console.error("Error en carga de dom:",o),t.error("Error al finalizar la carga")}).finally(()=>{})):t.error("Error al guardar el domicilio."),console.log(e)},()=>{console.log(C.errors),t.error("Por favor complete los campos obligatorios")}),style:{display:"grid",gridTemplateRows:"1fr max-content",rowGap:"10px",justifyContent:"center"},children:[i(J,{mode:"",control:L,dataPrc:I,cllId:M,prvId:x,locId:G,partId:B,barId:z,domObs:R,DomPuerta:T,getValues:O,isGoogleMapsOpen:!1,setIsGoogleMapsOpen:()=>{console.log("Mapa no habilitado")},triggerSeleccionarUbicacion:f,lat:j,lng:w,setValue:r,resetField:S,terminoCargaInicial:!0,mostrarCampo:["prv","loc","cll","bar","puerta","piso","depto","cp"],sinMapa:!0,disabled:!1},"datos-laborales-dom-form"),i(q,{variant:"contained",type:"submit",children:"Enviar"})]})})};export{ro as default};
