import{H as N,r as d,aW as U,h as V,j as i,aa as W,o as k,K as A,$ as p,m as l,W as t}from"./index-e717fda1.js";import{b as D,p as u}from"./env-198ff0f3.js";import{D as K,r as q}from"./DatosDom-ca00e8fb.js";import"./DialogContentText-37e6a459.js";const oo=({id:g})=>{const I=g||0,f=N(),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:M,LocId:R,PrvId:T,DomLat:F,DomLng:H,PartId:n,DomGoogleDet:m}=a;r("PrvId",T),r("DomCP",(o==null?void 0:o.toString())??""),r("LocId",R),r("CllId",s.toString()),r("DomPuerta",M),r("DomLat",F),r("DomLng",H),n!==void 0&&r("PartId",n),o!==void 0&&r("DomCP",o),m!==void 0&&r("DomGoogleDet",m)},{iprid:e}=U(),[h,c]=d.useState(1),{control:L,setValue:r,reset:v,handleSubmit:y,formState:C,watch:E,resetField:S}=V({defaultValues:{DomDet:"",PrvId:"",LocId:"",PartId:"",CllId:"",BarId:"",DomPuerta:"",DomCP:"",DomPiso:"",DomDepto:"",DomLat:"",DomLng:"",DomGoogleDet:"",DomObs:""}}),[O,j,w,x,G,$,z,B]=E(["DomLat","DomLng","PrvId","LocId","CllId","BarId","PartId","DomObs"]);return i(W,{children:k("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(K,{mode:"",control:L,dataPrc:I,cllId:G,prvId:w,locId:x,partId:z,barId:$,domObs:B,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(A,{variant:"contained",type:"submit",children:"Enviar"})]})})};export{oo as default};
