import{H,r as d,aW as N,h as U,j as i,aa as W,o as k,K as A,$ as p,m as l,W as t}from"./index-28356639.js";import{b as D,p as u}from"./env-198ff0f3.js";import{D as K,r as q}from"./DatosDom-f11d8bf3.js";import"./DialogContentText-8cf287af.js";const oo=({id:g})=>{const I=g||0,f=H(),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:V,DomLng:F,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",V),r("DomLng",F),n!==void 0&&r("PartId",n),o!==void 0&&r("DomCP",o),m!==void 0&&r("DomGoogleDet",m)},{iprid:e}=N(),[h,c]=d.useState(1),{control:L,setValue:r,reset:v,handleSubmit:y,formState:C,watch:E,resetField:S}=U({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(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: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(A,{variant:"contained",type:"submit",children:"Enviar"})]})})};export{oo as default};
