import{r as s,u as C,e as Q,j as e,N as D,l as c,t as d,W as R}from"./index-91e9700c.js";import{Q as v}from"./QrReader-c717eec2.js";import{B as o,C as S,R as j}from"./Container-952e9d4a.js";import{b as w,p as B}from"./env-198ff0f3.js";import{T as m}from"./Typography-05ee1d2d.js";import{D as E}from"./Divider-8c28b99a.js";import{B as f}from"./Button-66eac543.js";import{C as T}from"./CssVarsProvider-76410691.js";import"./useThemeProps-1bc4d723.js";import"./createContainer-1f2487c8.js";import"./useSlot-6d750ee3.js";import"./ThemeProvider-ef8f8c5f.js";const I=()=>{const[t,p]=s.useState(null),[n,u]=s.useState(null),[i,l]=s.useState(!1),{authFederal:h}=C(),g=()=>l(!i);Q({typography:{fontFamily:["Poppins","sans-serif"].join(",")}});const y=async r=>{r.preventDefault();const a=await R.post(`${w}/${B}/rest/federal/autorizar`,n,{withCredentials:!0});a.data.success?(d.success("Crédito federal autorizado correctamente"),p(null),l(!1)):d.error("Error: "+a.data.msg)};if(!h)return e(D,{to:"/federal-login"});s.useEffect(()=>{if(t){if(typeof t=="object")u(t);else if(typeof t=="string"){const r=x(t);r?u(r):console.warn("El contenido del QR no es un JSON válido.")}}},[t]);function x(r){try{const a=r.replace(/([{,]\s*)'([^']+?)'\s*:/g,'$1"$2":').replace(/:\s*'([^']+?)'/g,':"$1"');return JSON.parse(a)}catch(a){return console.error("Error al convertir qrData a JSON:",a),null}}return e(T,{children:e(o,{children:e(S,{maxWidth:"md",children:c(o,{sx:{paddingTop:"2em"},children:[e(m,{level:"h1",gutterBottom:!0,component:"h1",children:"Crédito Federal"}),e(E,{}),c(o,{sx:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"2em 0"},children:[e(m,{gutterBottom:!0,component:"h2",sx:{fontSize:"1.5em"},children:"Escaneo de QR de Crédito Federal"}),e(f,{variant:"solid",sx:{marginTop:"1em"},onClick:g,children:i?"Cerrar lector QR":"Abrir lector QR"}),i&&e(o,{mt:2,width:"100%",children:e(v,{setResultado:r=>{p(r),d.success("QR escaneado correctamente")},onClose:()=>l(!1)})}),n&&c(o,{mt:3,width:"100%",children:[e(m,{level:"body-lg",gutterBottom:!0,children:"Datos del crédito escaneado:"}),e(j,{src:n,name:!1,displayDataTypes:!1,theme:"monokai"}),e(f,{variant:"solid",sx:{marginTop:"1em"},onClick:y,children:"Autorizar"})]})]})]})})})})};export{I as default};
