import{i as S}from"./emotion-use-insertion-effect-with-fallbacks.browser.esm-2ce7a1bc.js";import{j as e,a,F,B as l}from"./Tooltip-5ec3092e.js";import{u as O,b as G,c as x,C as U,a as D}from"./Slide-ab750237.js";import{c as V,V as k,T as u,W as h,X as Y,L as P,G as d,b as _,N as C,m as p,i as $,Y as H,z as j,Z as Q}from"./index-50f78195.js";import{S as X,a as b,M as Z,b as J,g as K,c as aa,p as ra}from"./index-0e7e79ae.js";/* empty css                  */import{u as A}from"./_commonjs-dynamic-modules-83e41e9f.js";const{useRef:ea,useState:m}=await S("react"),{DialogActions:ia}=await S("@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),[z,I]=m(""),w=()=>{i.current?.clear()},R=V(),L=()=>{const c=i.current?.isEmpty(),T=i.current?.getTrimmedCanvas().toDataURL();if(c){d.error("Debe dibujar la firma");return}s(!0),I(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(""),aa(g,c.substring(22),{...q}).then(y=>{y.success?R("/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(X,{canvasProps:{width:t?300:450,height:n<900?200:400,className:"sigCanvas",throttle:30},penColor:"#0404e0",ref:i})}),a(b,{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(b,{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(Z,{open:v,onClose:()=>s(!1),children:e(J,{variant:"outlined",role:"alertdialog",children:[o==="Firma"&&e(F,{children:[a(G,{children:"Aviso"}),a(Y,{}),e(F,{children:[a(x,{children:"¿Estas seguro que quieres enviar esta firma?"}),a(x,{children:a("img",{src:z,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(P,{mensaje:"Enviando firma..."})})})]})})]})},{useEffect:sa,useState:E}=await S("react");ra.GlobalWorkerOptions.workerSrc=new URL("pdfjs-dist/build/pdf.worker.min.js",self.location).toString();const fa=()=>{const[g,i]=E(""),[v,s]=E([]),{authFirma:t,unAuthenticateSignature:n}=_(),{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(H,{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")):j.error("No se encontraron contratos a firmar, por favor recargue")}).catch(r=>{j.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(U,{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(Q.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(b,{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{fa as default};
