Files
finanzas/dist/_next/static/chunks/app/settings/page-88d3fd0faab66996.js

1 line
16 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[938],{5417:function(e,t,a){Promise.resolve().then(a.bind(a,9879))},9879:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return j}});var r=a(7437),s=a(2265),n=a(8755);let l=(0,n.Z)("save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);var i=a(2934);let o=(0,n.Z)("circle-x",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]),c=(0,n.Z)("bot",[["path",{d:"M12 8V4H8",key:"hb8ula"}],["rect",{width:"16",height:"12",x:"4",y:"8",rx:"2",key:"enze0r"}],["path",{d:"M2 14h2",key:"vft8re"}],["path",{d:"M20 14h2",key:"4cs60a"}],["path",{d:"M15 13v2",key:"1xurst"}],["path",{d:"M9 13v2",key:"rq6x2g"}]]);var d=a(1817),u=a(4743);let p=(0,n.Z)("key",[["path",{d:"m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4",key:"g0fldk"}],["path",{d:"m21 2-9.6 9.6",key:"1j0ho8"}],["circle",{cx:"7.5",cy:"15.5",r:"5.5",key:"yqb3hr"}]]),m=(0,n.Z)("message-square",[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]]);var x=a(9397);let h=(0,n.Z)("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]);var g=a(8930),y=a(6337);let f=(0,n.Z)("box",[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]]),b=(0,n.Z)("sparkles",[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]]);var v=a(4508);function j(){let[e,t]=(0,s.useState)(!0),[a,n]=(0,s.useState)(!1),[j,k]=(0,s.useState)({telegram:{botToken:"",chatId:""},aiProviders:[]}),[w,N]=(0,s.useState)(null),[M,Z]=(0,s.useState)(!1),[z,C]=(0,s.useState)(null),[P,T]=(0,s.useState)(null),[E,D]=(0,s.useState)({});(0,s.useEffect)(()=>{fetch("/api/settings").then(e=>e.json()).then(e=>{k(e),t(!1)}).catch(e=>{console.error(e),t(!1),N({text:"Error cargando configuraci\xf3n",type:"error"})})},[]);let S=async()=>{n(!0),N(null);try{if(!(await fetch("/api/settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j)})).ok)throw Error("Error saving");N({text:"Configuraci\xf3n guardada correctamente",type:"success"})}catch(e){N({text:"Error al guardar la configuraci\xf3n",type:"error"})}finally{n(!1)}},I=async()=>{Z(!0),N(null);try{let e=await fetch("/api/test/telegram",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(j.telegram)}),t=await e.json();t.success?N({text:"Mensaje de prueba enviado con \xe9xito ✅",type:"success"}):N({text:"Error: ".concat(t.error),type:"error"})}catch(e){N({text:"Error de conexi\xf3n al probar Telegram",type:"error"})}finally{Z(!1)}},A=async e=>{C(e.id),N(null);try{let t=await fetch("/api/test/ai",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),a=await t.json();a.success?N({text:"Conexi\xf3n exitosa con ".concat(e.model||e.name," (").concat(a.latency,"ms) ✅"),type:"success"}):N({text:"Error con ".concat(e.name,": ").concat(a.error),type:"error"})}catch(e){N({text:"Error al conectar con el proveedor",type:"error"})}finally{C(null)}},F=async e=>{T(e.id),N(null);try{let t=await fetch("/api/proxy/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({endpoint:e.endpoint,token:e.token})}),a=await t.json();a.success&&a.models.length>0?(D(t=>({...t,[e.id]:a.models})),e.model||q(e.id,"model",a.models[0]),N({text:"Se detectaron ".concat(a.models.length," modelos ✅"),type:"success"})):N({text:"No se pudieron detectar modelos. Ingr\xe9salo manualmente.",type:"error"})}catch(e){console.error(e),N({text:"Error al consultar modelos",type:"error"})}finally{T(null)}},O=e=>{k(t=>({...t,aiProviders:t.aiProviders.filter(t=>t.id!==e)}))},q=(e,t,a)=>{k(r=>({...r,aiProviders:r.aiProviders.map(r=>r.id===e?{...r,[t]:a}:r)}))};return e?(0,r.jsx)("div",{className:"p-8 text-center text-slate-400",children:"Cargando configuraci\xf3n..."}):(0,r.jsxs)("div",{className:"max-w-4xl mx-auto space-y-8 pb-10",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between",children:[(0,r.jsxs)("div",{children:[(0,r.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Configuraci\xf3n"}),(0,r.jsx)("p",{className:"text-slate-400 text-sm",children:"Gestiona la integraci\xf3n con Telegram e Inteligencia Artificial."})]}),(0,r.jsxs)("button",{onClick:S,disabled:a,className:"flex items-center gap-2 px-6 py-2 bg-emerald-500 hover:bg-emerald-400 text-white rounded-lg transition shadow-lg shadow-emerald-500/20 font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,r.jsx)(l,{size:18}),a?"Guardando...":"Guardar Cambios"]})]}),w&&(0,r.jsxs)("div",{className:(0,v.cn)("p-4 rounded-lg text-sm font-medium border flex items-center gap-2 animate-in fade-in slide-in-from-top-2","success"===w.type?"bg-emerald-500/10 border-emerald-500/20 text-emerald-400":"bg-red-500/10 border-red-500/20 text-red-400"),children:["success"===w.type?(0,r.jsx)(i.Z,{size:18}):(0,r.jsx)(o,{size:18}),w.text]}),(0,r.jsxs)("section",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between text-white border-b border-slate-800 pb-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(c,{className:"text-cyan-400"}),(0,r.jsx)("h2",{className:"text-lg font-semibold",children:"Telegram Bot"})]}),(0,r.jsxs)("button",{onClick:I,disabled:M||!j.telegram.botToken||!j.telegram.chatId,className:"text-xs flex items-center gap-1.5 bg-cyan-500/10 hover:bg-cyan-500/20 text-cyan-400 border border-cyan-500/20 px-3 py-1.5 rounded-lg transition disabled:opacity-50 disabled:cursor-not-allowed",children:[M?(0,r.jsx)(d.Z,{size:14,className:"animate-spin"}):(0,r.jsx)(u.Z,{size:14}),"Probar Env\xedo"]})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 p-6 bg-slate-900 border border-slate-800 rounded-xl",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider flex items-center gap-2",children:[(0,r.jsx)(p,{size:12})," Bot Token"]}),(0,r.jsx)("input",{type:"text",placeholder:"123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",value:j.telegram.botToken,onChange:e=>k({...j,telegram:{...j.telegram,botToken:e.target.value}}),className:"w-full px-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white font-mono text-sm outline-none transition-all placeholder:text-slate-700"}),(0,r.jsx)("p",{className:"text-[10px] text-slate-500",children:"El token que te da @BotFather."})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider flex items-center gap-2",children:[(0,r.jsx)(m,{size:12})," Chat ID"]}),(0,r.jsx)("input",{type:"text",placeholder:"123456789",value:j.telegram.chatId,onChange:e=>k({...j,telegram:{...j.telegram,chatId:e.target.value}}),className:"w-full px-4 py-3 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-cyan-500/50 focus:border-cyan-500 text-white font-mono text-sm outline-none transition-all placeholder:text-slate-700"}),(0,r.jsx)("p",{className:"text-[10px] text-slate-500",children:"Tu ID num\xe9rico de Telegram (o el ID del grupo)."})]})]})]}),(0,r.jsxs)("section",{className:"space-y-4",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between text-white border-b border-slate-800 pb-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(c,{className:"text-purple-400"}),(0,r.jsx)("h2",{className:"text-lg font-semibold",children:"Proveedores de IA"})]}),(0,r.jsxs)("button",{onClick:()=>{j.aiProviders.length>=3||k(e=>({...e,aiProviders:[...e.aiProviders,{id:crypto.randomUUID(),name:"",endpoint:"",token:"",model:""}]}))},disabled:j.aiProviders.length>=3,className:"text-xs flex items-center gap-1 bg-slate-800 hover:bg-slate-700 text-slate-200 px-3 py-1.5 rounded-lg transition disabled:opacity-50 disabled:cursor-not-allowed",children:[(0,r.jsx)(x.Z,{size:14})," Agregar Provider (",j.aiProviders.length,"/3)"]})]}),(0,r.jsxs)("div",{className:"space-y-4",children:[0===j.aiProviders.length&&(0,r.jsx)("div",{className:"p-8 text-center text-slate-500 border border-dashed border-slate-800 rounded-xl",children:"No hay proveedores de IA configurados. Agrega uno para empezar."}),j.aiProviders.map((e,t)=>(0,r.jsxs)("div",{className:"p-6 bg-slate-900 border border-slate-800 rounded-xl relative group",children:[(0,r.jsxs)("div",{className:"flex justify-between items-start mb-4",children:[(0,r.jsxs)("h3",{className:"text-sm font-semibold text-slate-300 bg-slate-950 inline-block px-3 py-1 rounded-md border border-slate-800",children:["Provider #",t+1]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)("button",{onClick:()=>A(e),disabled:z===e.id||!e.endpoint||!e.token||!e.model,className:(0,v.cn)("text-xs flex items-center gap-1 bg-slate-800 hover:bg-slate-700 text-purple-300 border border-purple-500/20 px-2 py-1.5 rounded-lg transition disabled:opacity-50",!e.model&&"opacity-50"),title:"Verificar conexi\xf3n",children:[z===e.id?(0,r.jsx)(d.Z,{size:12,className:"animate-spin"}):(0,r.jsx)(h,{size:12}),"Test"]}),(0,r.jsx)("button",{onClick:()=>O(e.id),className:"text-slate-500 hover:text-red-400 transition-colors p-1.5 hover:bg-red-500/10 rounded-lg",title:"Eliminar",children:(0,r.jsx)(g.Z,{size:16})})]})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider",children:"Nombre"}),(0,r.jsx)("input",{type:"text",placeholder:"Ej: MiniMax, Z.ai",value:e.name,onChange:t=>q(e.id,"name",t.target.value),className:"w-full px-4 py-2.5 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-purple-500/50 focus:border-purple-500 text-white text-sm outline-none"})]}),(0,r.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider flex items-center gap-2",children:[(0,r.jsx)(h,{size:12})," Endpoint URL"]}),(0,r.jsx)("input",{type:"text",placeholder:"https://api.example.com/v1",value:e.endpoint,onChange:t=>q(e.id,"endpoint",t.target.value),className:"w-full px-4 py-2.5 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-purple-500/50 focus:border-purple-500 text-white font-mono text-sm outline-none"})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider flex items-center gap-2",children:[(0,r.jsx)(y.Z,{size:12})," API Key / Token"]}),(0,r.jsx)("input",{type:"password",placeholder:"sk-...",value:e.token,onChange:t=>q(e.id,"token",t.target.value),className:"w-full px-4 py-2.5 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-purple-500/50 focus:border-purple-500 text-white font-mono text-sm outline-none"})]})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex justify-between items-center",children:[(0,r.jsxs)("label",{className:"text-xs font-medium text-slate-400 uppercase tracking-wider flex items-center gap-2",children:[(0,r.jsx)(f,{size:12})," Model"]}),(0,r.jsxs)("button",{onClick:()=>F(e),disabled:P===e.id||!e.endpoint||!e.token,className:"text-[10px] flex items-center gap-1 text-cyan-400 hover:text-cyan-300 disabled:opacity-50",children:[P===e.id?(0,r.jsx)(d.Z,{size:10,className:"animate-spin"}):(0,r.jsx)(b,{size:10}),"Auto Detectar"]})]}),E[e.id]?(0,r.jsxs)("select",{value:e.model||"",onChange:t=>q(e.id,"model",t.target.value),className:"w-full px-4 py-2.5 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-purple-500/50 focus:border-purple-500 text-white text-sm outline-none",children:[(0,r.jsx)("option",{value:"",disabled:!0,children:"Selecciona un modelo"}),E[e.id].map(e=>(0,r.jsx)("option",{value:e,children:e},e))]}):(0,r.jsx)("input",{type:"text",placeholder:"Ej: gpt-3.5-turbo, glm-4",value:e.model||"",onChange:t=>q(e.id,"model",t.target.value),className:"w-full px-4 py-2.5 bg-slate-950 border border-slate-800 rounded-lg focus:ring-2 focus:ring-purple-500/50 focus:border-purple-500 text-white font-mono text-sm outline-none"})]})]})]},e.id))]})]})]})}},4508:function(e,t,a){"use strict";a.d(t,{Ic:function(){return m},JG:function(){return c},P8:function(){return o},PW:function(){return h},Q0:function(){return p},ZY:function(){return d},cn:function(){return n},iS:function(){return i},tk:function(){return x},w7:function(){return g},xG:function(){return l},zF:function(){return u}});var r=a(1994),s=a(3335);function n(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];return(0,s.m6)((0,r.W)(t))}function l(e){return new Intl.NumberFormat("es-AR",{style:"currency",currency:"ARS",minimumFractionDigits:2,maximumFractionDigits:2}).format(e)}function i(e){let t="string"==typeof e?new Date(e):e;return new Intl.DateTimeFormat("es-AR",{day:"2-digit",month:"2-digit",year:"numeric"}).format(t)}function o(e){let t="string"==typeof e?new Date(e):e,a=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()),s=new Date(a.getFullYear(),a.getMonth(),a.getDate());return Math.ceil((r.getTime()-s.getTime())/864e5)}function c(e){let t=new Date,a=t.getFullYear(),r=t.getMonth(),s=t.getDate(),n=a,l=r;s>e&&(l+=1)>11&&(l=0,n+=1);let i=new Date(n,l+1,0).getDate();return new Date(n,l,Math.min(e,i))}function d(e){if(e<1||e>12)throw Error("El mes debe estar entre 1 y 12");return["enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"][e-1]}function u(e){return e.filter(e=>!e.isPaid).reduce((e,t)=>e+t.amount,0)}function p(e){return e.filter(e=>!e.isPaid).reduce((e,t)=>e+t.amount,0)}function m(e,t){return(t?e.filter(e=>e.cardId===t):e).reduce((e,t)=>e+t.amount,0)}function x(e){return c(e)}function h(e){return c(e)}function g(e,t){return t<=0?0:Math.min(Math.max(e/t*100,0),100)}},2934:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});let r=(0,a(8755).Z)("circle-check",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]])},1817:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});let r=(0,a(8755).Z)("loader-circle",[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]])},6337:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});let r=(0,a(8755).Z)("lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]])},9397:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});let r=(0,a(8755).Z)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},4743:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});let r=(0,a(8755).Z)("send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]])},8930:function(e,t,a){"use strict";a.d(t,{Z:function(){return r}});let r=(0,a(8755).Z)("trash-2",[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]])}},function(e){e.O(0,[697,971,117,744],function(){return e(e.s=5417)}),_N_E=e.O()}]);