import{H as F,r as d,aU as H,h as N,j as i,a9 as k,o as A,K,$ as p,m as l,W as t}from"./index-62412d73.js";import{b as D,p as u}from"./env-198ff0f3.js";import{D as W,r as q}from"./DatosDom-8064dda9.js";import"./Close-45a41f0c.js";import"./DialogContentText-3747410b.js";const ro=({id:g})=>{const I=g||0,f=F(),b=a=>{P(a)};d.useEffect(()=>{(async()=>{try{const s=await p.post(`${D}/${u}/rest/mensajesPaperless/creaSession`,{iprid:e});await l.getData(parseInt(e),["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(s){t.error("Error al actualizar domicilio"),console.error(s)}})()},[]);const P=a=>{v();const{CllId:s,DomCP:o,DomPuerta:R,LocId:T,PrvId:z,DomLat:U,DomLng:V,PartId:n,DomGoogleDet:m}=a;r("PrvId",z),r("DomCP",(o==null?void 0:o.toString())??""),r("LocId",T),r("CllId",s.toString()),r("DomPuerta",R),r("DomLat",U),r("DomLng",V),n!==void 0&&r("PartId",n),o!==void 0&&r("DomCP",o),m!==void 0&&r("DomGoogleDet",m)},{iprid:e}=H(),[h,c]=d.useState(1),{control:L,setValue:r,reset:v,handleSubmit:y,formState:C,watch:E,resetField:S}=N({defaultValues:{DomDet:"",PrvId:"",LocId:"",PartId:"",CllId:"",BarId:"",DomPuerta:"",DomCP:"",DomPiso:"",DomDepto:"",DomLat:"",DomLng:"",DomGoogleDet:"",DomObs:""}}),[O,j,w,x,G,$,B,M]=E(["DomLat","DomLng","PrvId","LocId","CllId","BarId","PartId","DomObs"]);return i(k,{children:A("form",{hidden:h!==1,onSubmit:y(async a=>{console.log(a);const s=await q.guardar("Dom",{data:[{...a,DomObs:l.isTruthy(a.DomObs)?a.DomObs:"null",DomTip:"PAR"}],iprId:Number.parseInt(e===void 0?"":e)});s.success?(t.success("Domicilio guardadfo con exito."),await p.post(`${D}/${u}/rest/mensajesPaperless/actualizaProc`,{iprid:e}).then(o=>{c(0),f("/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(s)},()=>{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(W,{mode:"",control:L,dataPrc:I,cllId:G,prvId:w,locId:x,partId:B,barId:$,domObs:M,isGoogleMapsOpen:!1,setIsGoogleMapsOpen:()=>{console.log("Mapa no habilitado")},triggerSeleccionarUbicacion:b,lat:O,lng:j,setValue:r,resetField:S,terminoCargaInicial:!0,mostrarCampo:["prv","loc","cll","bar","puerta","piso","depto","cp"],sinMapa:!0,disabled:!1},"datos-laborales-dom-form"),i(K,{variant:"contained",type:"submit",children:"Enviar"})]})})};export{ro as default};
