import{i as b}from"./emotion-use-insertion-effect-with-fallbacks.browser.esm-6809063d.js";import{j as e,a,F,B as l}from"./Tooltip-ae8d7992.js";import{u as O,b as U,c as x,C as V,a as D}from"./Slide-2a94fa39.js";import{c as G,R as k,T as u,S as h,V as P,E as d,b as Y,N as C,m as p,i as _,W as $,z as E,X as H}from"./index-dfa17bed.js";import{S as Q,a as S,M as X,b as J,g as K,c as Z,p as aa}from"./index-a74e9cad.js";/* empty css                  */import{u as A}from"./_commonjs-dynamic-modules-63bfb144.js";import{L as ra}from"./Loader-45efafef.js";const{useRef:ea,useState:m}=await b("react"),{DialogActions:ia}=await b("@mui/material"),ta=({idFirma:g})=>{const i=ea(null),[v,s]=m(!1),t=O("(max-width:500px)"),{height:n,width:B}=A(200),[o,r]=m("Firma"),[na,M]=m("Alerta"),[N,f]=m(!1),[R,z]=m(""),w=()=>{i.current?.clear()},I=G(),L=()=>{const c=i.current?.isEmpty(),T=i.current?.getTrimmedCanvas().toDataURL();if(c){d.error("Debe dibujar la firma");return}s(!0),z(T)},W=()=>{f(!0);const c=i.current?.getTrimmedCanvas().toDataURL();if(i.current?.isEmpty()){d.error("Debe dibujar la firma"),f(!1);return}if(c.substring(22).length<1500){d.error("No pudimos procesar firma realizada, necesitamos que lo vuelva a intentar. Intente que la firma sea clara"),f(!1),w(),s(!1);return}if(c){const q=K();r("Verificando"),M(""),Z(g,c.substring(22),{...q}).then(y=>{y.success?I("/firma-success-simple",{replace:!0}):(f(!0),r("Firma"),d.error("Error al enviar la firma"),s(!1))}).catch(y=>{r("Firma"),console.error("Error en firmarDocs:",y),d.error("Error al enviar la firma")}).finally(()=>{})}};return e(k,{children:[e("div",{style:{paddingTop:n<=560?"0.5em":"1em"},children:[a(u,{variant:"caption",display:"block",gutterBottom:!0,children:"Realizar firma aqui"}),a("div",{style:{border:"2px solid #ccc",borderRadius:"8px",width:t?300:450,height:n<900?250:400,marginBottom:"0.5em",backgroundColor:"#FDFBF5"},children:a(Q,{canvasProps:{width:t?300:450,height:n<900?200:400,className:"sigCanvas",throttle:30},penColor:"#0404e0",ref:i})}),a(S,{direction:{xs:n<610?"row":"column",sm:"row"},spacing:{xs:1,sm:2,md:4},justifyContent:"center",children:a("div",{style:{paddingBottom:"40px"},children:e(S,{direction:{xs:n<610?"row":"column",sm:"row"},spacing:{xs:2,sm:2,md:4},children:[a(h,{size:"sm",variant:"solid",color:"danger",onClick:w,children:"Borrar Firma"}),a(h,{size:"sm",variant:"solid",color:"primary",onClick:L,children:"Enviar Firma"})]})})})]}),a(X,{open:v,onClose:()=>s(!1),children:e(J,{variant:"outlined",role:"alertdialog",children:[o==="Firma"&&e(F,{children:[a(U,{children:"Aviso"}),a(P,{}),e(F,{children:[a(x,{children:"¿Estas seguro que quieres enviar esta firma?"}),a(x,{children:a("img",{src:R,alt:"imagen firma"})}),e(ia,{children:[a(h,{onClick:()=>s(!1),variant:"outlined",color:"danger",children:"No"}),a(h,{onClick:W,color:"primary",variant:"solid",disabled:N,children:"Si"})]})]})]}),o==="Verificando"&&a(F,{children:a(x,{children:a(ra,{mensaje:"Enviando firma..."})})})]})})]})},{useEffect:sa,useState:j}=await b("react");aa.GlobalWorkerOptions.workerSrc=new URL("pdfjs-dist/build/pdf.worker.min.js",self.location).toString();const pa=()=>{const[g,i]=j(""),[v,s]=j([]),{authFirma:t,unAuthenticateSignature:n}=Y(),{width:B,height:o}=A(200);if(t)if(p.isTruthy(t.idFirma)){if(t.firmado)return a(C,{to:"/firmados-simple"})}else return a(C,{to:"/firma-verificar-simple"});else return a(C,{to:"/firma-verificar-simple"});return sa(()=>{_.post($,{iprId:t.idTramite}).then(r=>{r.data.success&&p.isTruthy(r.data.data)?(p.isTruthy(r.data.data.contratos)&&s(r.data.data.contratos),p.isTruthy(r.data.data.leyenda)?i(r.data.data.leyenda):i("Bienvenido a la plataforma de firma")):E.error("No se encontraron contratos a firmar, por favor recargue")}).catch(r=>{E.error("Hubo un error interno al recuperar información de contratos a firmar"),console.error(r)})},[]),a(k,{children:a(l,{sx:{backgroundColor:"#F4F5FA",height:"100dvh"},children:a(V,{maxWidth:"xl",children:a(l,{sx:{},children:e(l,{sx:{paddingTop:"1em"},children:[e(l,{display:"flex",justifyContent:"space-between",children:[a(u,{color:"neutral",level:o<660?"h2":"h1",noWrap:!1,variant:"plain",children:"Firma"}),a(h,{onClick:()=>n(H.FIRMA_SIN_DOCUMENTOS),variant:"plain",size:"sm",children:"Salir"})]}),a(D,{}),e(l,{sx:{marginY:o<660?"1em":"1.5em"},children:[a(u,{color:"neutral",level:o<660?"h3":"h1",noWrap:!1,variant:"plain",children:g}),a(u,{level:"title-lg",children:"Contratos a firmar"}),a(S,{sx:{marginY:"1em",overflow:"scroll",height:o<730?"70px":"100px"},spacing:2,children:v.map(r=>a(u,{children:r.AdjTipNom},r.AdjTipId))})]}),a(D,{}),a(l,{sx:{display:"flex",justifyContent:"center"},children:a(ta,{idFirma:t.idFirma})})]})})})})})};export{pa as default};
