import{r as a,u as D,i as x,j as e,N as Q,ba as R,o as u,p,z as m,$ as S}from"./index-7722cded.js";import{Q as v}from"./QrReader-3bd9f426.js";import{B as s,C as T,R as A}from"./main-1948dbc2.js";import{b as E,p as j}from"./env-198ff0f3.js";import{D as z}from"./Divider-f26c3e54.js";import{B as h}from"./Button-fa0668f6.js";const J=()=>{const[r,i]=a.useState(null),[c,f]=a.useState(null),[l,d]=a.useState(!1),{authFederal:n}=D(),g=()=>d(!l);x({typography:{fontFamily:["Poppins","sans-serif"].join(",")}});const y=async t=>{t.preventDefault();const o=await S.post(`${E}/${j}/rest/federal/autorizar`,c,{headers:{"Content-Type":"application/json",Authorization:`${(n==null?void 0:n.token)||""}`},withCredentials:!0});o.data.success?(m.success("Crédito federal autorizado correctamente"),i(null),d(!1)):m.error("Error: "+o.data.msg)};if(!n)return e(Q,{to:"/federal-unauthenticate",replace:!0});a.useEffect(()=>{if(r){if(typeof r=="object")f(r);else if(typeof r=="string"){const t=C(r);t?f(t):console.warn("El contenido del QR no es un JSON válido.")}}},[r]);function C(t){try{const o=t.replace(/([{,]\s*)'([^']+?)'\s*:/g,'$1"$2":').replace(/:\s*'([^']+?)'/g,':"$1"');return JSON.parse(o)}catch(o){return console.error("Error al convertir qrData a JSON:",o),null}}return a.useEffect(()=>{i({"Monto Solicitado":"20000",Plazo:"12",Fecha:"2025-06-12T11:38:42.418","Tipo de Documento":"DNI","Nombre del Agente":"MARIA JUDITH IBAÑEZ",Documento:"33190477","Codigo de cuenta":"229906",SolId:"86872"})},[]),e(R,{children:e(s,{children:e(T,{maxWidth:"md",children:u(s,{sx:{paddingTop:"2em"},children:[e(p,{level:"h1",gutterBottom:!0,component:"h1",children:"Crédito Federal"}),e(z,{}),u(s,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"2em 0"},children:[e(p,{gutterBottom:!0,component:"h2",sx:{fontSize:"1.5em"},children:"Escaneo de QR de Crédito Federal"}),e(h,{variant:"solid",sx:{marginTop:"1em"},onClick:g,children:l?"Cerrar lector QR":"Abrir lector QR"}),l&&e(s,{mt:2,width:"100%",children:e(v,{setResultado:t=>{i(t),m.success("QR escaneado correctamente")},onClose:()=>d(!1)})}),c&&u(s,{mt:3,width:"100%",children:[e(p,{level:"body-lg",gutterBottom:!0,children:"Datos del crédito escaneado:"}),e(A,{src:c,name:!1,displayDataTypes:!1,theme:"monokai"}),e(h,{variant:"solid",sx:{marginTop:"1em"},onClick:y,children:"Autorizar"})]})]})]})})})})};export{J as default};
