import{x as F,r as d,aN as U,d as k,j as i,l as A,z as H,W as p,i as l,K as s}from"./index-91e9700c.js";import{b as D,p as u}from"./env-198ff0f3.js";import{D as K,r as W}from"./DatosDom-1b7497dd.js";import{C as q}from"./Container-3bb74340.js";import"./Close-84438d62.js";import"./DialogContentText-3801f418.js";import"./Divider-d0fc16ba.js";import"./createContainer-1f2487c8.js";const so=({id:g})=>{const I=g||0,f=F(),b=a=>{P(a)};d.useEffect(()=>{(async()=>{try{const t=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)&&(s.error("Domicilio ya cargado"),c(0))}).catch(o=>{s.error("Error al recuperar datos de solicitud"),console.error(o)})}catch(t){s.error("Error al actualizar domicilio"),console.error(t)}})()},[]);const P=a=>{v();const{CllId:t,DomCP:o,DomPuerta:R,LocId:T,PrvId:$,DomLat:N,DomLng:V,PartId:n,DomGoogleDet:m}=a;r("PrvId",$),r("DomCP",(o==null?void 0:o.toString())??""),r("LocId",T),r("CllId",t.toString()),r("DomPuerta",R),r("DomLat",N),r("DomLng",V),n!==void 0&&r("PartId",n),o!==void 0&&r("DomCP",o),m!==void 0&&r("DomGoogleDet",m)},{iprid:e}=U(),[L,c]=d.useState(1),{control:h,setValue:r,reset:v,handleSubmit:y,formState:C,watch:E,resetField:S}=k({defaultValues:{DomDet:"",PrvId:"",LocId:"",PartId:"",CllId:"",BarId:"",DomPuerta:"",DomCP:"",DomPiso:"",DomDepto:"",DomLat:"",DomLng:"",DomGoogleDet:"",DomObs:""}}),[x,O,j,w,G,z,B,M]=E(["DomLat","DomLng","PrvId","LocId","CllId","BarId","PartId","DomObs"]);return i(q,{children:A("form",{hidden:L!==1,onSubmit:y(async a=>{console.log(a);const t=await W.guardar("Dom",{data:[{...a,DomObs:l.isTruthy(a.DomObs)?a.DomObs:"null",DomTip:"PAR"}],iprId:Number.parseInt(e===void 0?"":e)});t.success?(s.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),s.error("Error al finalizar la carga")}).finally(()=>{})):s.error("Error al guardar el domicilio."),console.log(t)},()=>{console.log(C.errors),s.error("Por favor complete los campos obligatorios")}),style:{display:"grid",gridTemplateRows:"1fr max-content",rowGap:"10px",justifyContent:"center"},children:[i(K,{mode:"",control:h,dataPrc:I,cllId:G,prvId:j,locId:w,partId:B,barId:z,domObs:M,isGoogleMapsOpen:!1,setIsGoogleMapsOpen:()=>{console.log("Mapa no habilitado")},triggerSeleccionarUbicacion:b,lat:x,lng:O,setValue:r,resetField:S,terminoCargaInicial:!0,mostrarCampo:["prv","loc","cll","bar","puerta","piso","depto","cp"],sinMapa:!0,disabled:!1},"datos-laborales-dom-form"),i(H,{variant:"contained",type:"submit",children:"Enviar"})]})})};export{so as default};
