Files
finanzas/dist/_next/static/chunks/app/budget/page-1c1157916eee3b45.js

1 line
15 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[379],{2257:function(e,s,t){Promise.resolve().then(t.bind(t,7268))},7268:function(e,s,t){"use strict";t.r(s),t.d(s,{default:function(){return k}});var a=t(7437),l=t(553),n=t(2265),r=t(4508);let o=Array.from({length:12},(e,s)=>({value:s+1,label:(0,r.ZY)(s+1)}));function i(e){let{onSubmit:s,onCancel:t,initialData:l}=e,i=new Date,[d,c]=(0,n.useState)({totalIncome:(null==l?void 0:l.totalIncome)||0,savingsGoal:(null==l?void 0:l.savingsGoal)||0,month:(null==l?void 0:l.month)||i.getMonth()+1,year:(null==l?void 0:l.year)||i.getFullYear()}),[x,m]=(0,n.useState)({}),u=()=>{let e={};return d.totalIncome<=0&&(e.totalIncome="Los ingresos deben ser mayores a 0"),d.savingsGoal>=d.totalIncome&&(e.savingsGoal="La meta de ahorro debe ser menor que los ingresos"),(d.month<1||d.month>12)&&(e.month="El mes debe estar entre 1 y 12"),(d.year<2e3||d.year>2100)&&(e.year="El a\xf1o no es v\xe1lido"),m(e),0===Object.keys(e).length},h=(e,s)=>{c(t=>({...t,[e]:s})),x[e]&&m(s=>{let t={...s};return delete t[e],t})};return(0,a.jsxs)("form",{onSubmit:e=>{e.preventDefault(),u()&&s({month:d.month,year:d.year,totalIncome:d.totalIncome,savingsGoal:d.savingsGoal,fixedExpenses:(null==l?void 0:l.fixedExpenses)||0,variableExpenses:(null==l?void 0:l.variableExpenses)||0})},className:"space-y-4",children:[(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{htmlFor:"month",className:"block text-sm font-medium text-slate-300 mb-1",children:["Mes ",(0,a.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,a.jsx)("select",{id:"month",value:d.month,onChange:e=>h("month",parseInt(e.target.value)),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border rounded-lg text-white","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500",x.month?"border-red-500":"border-slate-600"),children:o.map(e=>(0,a.jsx)("option",{value:e.value,children:e.label},e.value))}),x.month&&(0,a.jsx)("p",{className:"mt-1 text-sm text-red-400",children:x.month})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{htmlFor:"year",className:"block text-sm font-medium text-slate-300 mb-1",children:["A\xf1o ",(0,a.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,a.jsx)("input",{type:"number",id:"year",min:"2000",max:"2100",value:d.year,onChange:e=>h("year",parseInt(e.target.value)||i.getFullYear()),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border rounded-lg text-white","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500",x.year?"border-red-500":"border-slate-600")}),x.year&&(0,a.jsx)("p",{className:"mt-1 text-sm text-red-400",children:x.year})]})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{htmlFor:"totalIncome",className:"block text-sm font-medium text-slate-300 mb-1",children:["Ingresos totales ",(0,a.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,a.jsx)("input",{type:"number",id:"totalIncome",min:"0",step:"0.01",value:d.totalIncome||"",onChange:e=>h("totalIncome",parseFloat(e.target.value)||0),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border rounded-lg text-white placeholder-slate-500","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500",x.totalIncome?"border-red-500":"border-slate-600"),placeholder:"0.00"}),x.totalIncome&&(0,a.jsx)("p",{className:"mt-1 text-sm text-red-400",children:x.totalIncome})]}),(0,a.jsxs)("div",{children:[(0,a.jsxs)("label",{htmlFor:"savingsGoal",className:"block text-sm font-medium text-slate-300 mb-1",children:["Meta de ahorro ",(0,a.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,a.jsx)("input",{type:"number",id:"savingsGoal",min:"0",step:"0.01",value:d.savingsGoal||"",onChange:e=>h("savingsGoal",parseFloat(e.target.value)||0),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border rounded-lg text-white placeholder-slate-500","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500",x.savingsGoal?"border-red-500":"border-slate-600"),placeholder:"0.00"}),x.savingsGoal&&(0,a.jsx)("p",{className:"mt-1 text-sm text-red-400",children:x.savingsGoal}),d.totalIncome>0&&(0,a.jsxs)("p",{className:"mt-1 text-sm text-slate-500",children:["Disponible para gastos: ",((d.totalIncome-d.savingsGoal)/d.totalIncome*100).toFixed(0),"%"]})]}),(0,a.jsxs)("div",{className:"flex gap-3 pt-2",children:[(0,a.jsx)("button",{type:"button",onClick:t,className:(0,r.cn)("flex-1 px-4 py-2 bg-slate-700 text-slate-200 rounded-lg font-medium","hover:bg-slate-600 transition-colors"),children:"Cancelar"}),(0,a.jsx)("button",{type:"submit",className:(0,r.cn)("flex-1 px-4 py-2 bg-blue-600 text-white rounded-lg font-medium","hover:bg-blue-500 transition-colors"),children:l?"Guardar cambios":"Crear presupuesto"})]})]})}function d(e){let{spent:s,total:t,label:l}=e,n=t>0?Math.min(s/t*100,100):0,o=n<70?{stroke:"#10b981",bg:"text-emerald-400"}:n<90?{stroke:"#f59e0b",bg:"text-amber-400"}:{stroke:"#ef4444",bg:"text-red-400"},i=148*Math.PI;return(0,a.jsxs)("div",{className:"flex flex-col items-center",children:[(0,a.jsxs)("div",{className:"relative",children:[(0,a.jsxs)("svg",{width:160,height:160,className:"transform -rotate-90",children:[(0,a.jsx)("circle",{stroke:"#334155",strokeWidth:12,fill:"transparent",r:74,cx:80,cy:80}),(0,a.jsx)("circle",{stroke:o.stroke,strokeWidth:12,strokeLinecap:"round",fill:"transparent",r:74,cx:80,cy:80,style:{strokeDasharray:"".concat(i," ").concat(i),strokeDashoffset:i-n/100*i,transition:"stroke-dashoffset 0.5s ease-in-out"}})]}),(0,a.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[(0,a.jsxs)("span",{className:(0,r.cn)("text-3xl font-bold",o.bg),children:[n.toFixed(0),"%"]}),(0,a.jsx)("span",{className:"text-slate-400 text-sm mt-1",children:"usado"})]})]}),(0,a.jsxs)("div",{className:"mt-4 text-center",children:[(0,a.jsx)("p",{className:"text-slate-400 text-sm",children:l}),(0,a.jsxs)("p",{className:"text-lg font-semibold text-white mt-1",children:[(0,r.xG)(s)," ",(0,a.jsxs)("span",{className:"text-slate-500",children:["/ ",(0,r.xG)(t)]})]}),(0,a.jsxs)("p",{className:"text-sm text-slate-500 mt-1",children:[(0,r.xG)(Math.max(t-s,0))," disponible"]})]})]})}function c(e){let{current:s,max:t,label:l,color:n}=e,o=t>0?Math.min(s/t*100,100):0;return(0,a.jsxs)("div",{className:"w-full",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-slate-300",children:l}),(0,a.jsxs)("span",{className:"text-sm text-slate-400",children:[(0,r.xG)(s)," ",(0,a.jsxs)("span",{className:"text-slate-600",children:["/ ",(0,r.xG)(t)]})]})]}),(0,a.jsx)("div",{className:"h-3 bg-slate-700 rounded-full overflow-hidden",children:(0,a.jsx)("div",{className:(0,r.cn)("h-full rounded-full transition-all duration-500 ease-out",n||(o<70?"bg-emerald-500":o<90?"bg-amber-500":"bg-red-500")),style:{width:"".concat(o,"%")}})}),(0,a.jsxs)("div",{className:"flex justify-between mt-1",children:[(0,a.jsxs)("span",{className:"text-xs text-slate-500",children:[o.toFixed(0),"% usado"]}),o>=100&&(0,a.jsx)("span",{className:"text-xs text-red-400 font-medium",children:"L\xedmite alcanzado"})]})]})}var x=t(525),m=t(3085),u=t(8755);let h=(0,u.Z)("minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);function b(e){let{label:s,amount:t,trend:l="neutral",color:n}=e;return(0,a.jsxs)("div",{className:"bg-slate-800 border border-slate-700/50 rounded-lg p-4",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("p",{className:"text-slate-400 text-sm",children:s}),(()=>{switch(l){case"up":return(0,a.jsx)(x.Z,{className:"w-4 h-4 text-emerald-400"});case"down":return(0,a.jsx)(m.Z,{className:"w-4 h-4 text-red-400"});default:return(0,a.jsx)(h,{className:"w-4 h-4 text-slate-500"})}})()]}),(0,a.jsx)("p",{className:(0,r.cn)("text-2xl font-mono font-semibold mt-2",n||"text-white"),children:(0,r.xG)(t)}),(0,a.jsx)("div",{className:"mt-2",children:(()=>{switch(l){case"up":return(0,a.jsx)("span",{className:"text-emerald-400 text-xs",children:"Positivo"});case"down":return(0,a.jsx)("span",{className:"text-red-400 text-xs",children:"Negativo"});default:return(0,a.jsx)("span",{className:"text-slate-500 text-xs",children:"Neutral"})}})()})]})}var p=t(4835),j=t(1804),f=t(9397);let g=(0,u.Z)("pen-line",[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]);var v=t(9322);function N(){let[e,s]=(0,n.useState)(!1),[t,l]=(0,n.useState)(!1),{monthlyBudgets:o,fixedDebts:m,variableDebts:u,cardPayments:h,currentMonth:N,currentYear:y,setMonthlyBudget:w}=(0,p.J)(),k=(0,n.useMemo)(()=>o.find(e=>e.month===N&&e.year===y),[o,N,y]),G=(0,n.useMemo)(()=>(0,r.zF)(m),[m]),I=(0,n.useMemo)(()=>(0,r.Q0)(u),[u]),M=(0,n.useMemo)(()=>(0,r.Ic)(h),[h]),C=G+I+M,Z=(null==k?void 0:k.totalIncome)||0,D=(null==k?void 0:k.savingsGoal)||0,E=Z-D,F=E-C,P=new Date(y,N,0).getDate(),z=new Date().getDate(),L=P-z,S=z>0?C/z:0,A=C+S*L,Y=()=>{s(!1),l(!1)},_=e=>{w(e),Y()};return k?(0,a.jsxs)("div",{className:"bg-slate-900 min-h-screen p-6",children:[(0,a.jsxs)("div",{className:"max-w-4xl mx-auto",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Presupuesto Mensual"}),(0,a.jsxs)("p",{className:"text-slate-400 text-sm mt-1",children:[(0,r.ZY)(N)," ",y]})]}),(0,a.jsxs)("button",{onClick:()=>{l(!0),s(!0)},className:(0,r.cn)("flex items-center gap-2 px-4 py-2 bg-slate-700 text-white rounded-lg font-medium","hover:bg-slate-600 transition-colors"),children:[(0,a.jsx)(g,{className:"w-4 h-4"}),"Editar"]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[(0,a.jsx)(b,{label:"Ingresos totales",amount:Z,trend:"up",color:"text-emerald-400"}),(0,a.jsx)(b,{label:"Meta de ahorro",amount:D,trend:"neutral",color:"text-blue-400"}),(0,a.jsx)(b,{label:"Gastado",amount:C,trend:C>E?"down":"neutral",color:C>E?"text-red-400":"text-amber-400"}),(0,a.jsx)(b,{label:"Disponible",amount:F,trend:F>0?"up":"down",color:F>0?"text-emerald-400":"text-red-400"})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mb-6",children:[(0,a.jsx)("div",{className:"bg-slate-800 border border-slate-700/50 rounded-lg p-6 flex items-center justify-center",children:(0,a.jsx)(d,{spent:C,total:E,label:"Presupuesto mensual"})}),(0,a.jsxs)("div",{className:"bg-slate-800 border border-slate-700/50 rounded-lg p-6",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-white mb-4",children:"Desglose de gastos"}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(c,{current:G,max:E,label:"Deudas fijas pendientes"}),(0,a.jsx)(c,{current:I,max:E,label:"Deudas variables pendientes"}),(0,a.jsx)(c,{current:M,max:E,label:"Pagos de tarjetas"})]})]})]}),(0,a.jsx)("div",{className:"bg-slate-800 border border-slate-700/50 rounded-lg p-6",children:(0,a.jsxs)("div",{className:"flex items-start gap-3",children:[(0,a.jsx)("div",{className:(0,r.cn)("p-2 rounded-lg",A>E?"bg-red-500/10":"bg-emerald-500/10"),children:A>E?(0,a.jsx)(v.Z,{className:"w-5 h-5 text-red-400"}):(0,a.jsx)(x.Z,{className:"w-5 h-5 text-emerald-400"})}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg font-semibold text-white",children:"Proyecci\xf3n"}),(0,a.jsxs)("p",{className:"text-slate-400 mt-1",children:["A tu ritmo actual de gasto (",(0,r.xG)(S),"/d\xeda),",A>E?(0,a.jsxs)("span",{className:"text-red-400",children:[" ","terminar\xe1s el mes con un d\xe9ficit de ",(0,r.xG)(A-E),"."]}):(0,a.jsxs)("span",{className:"text-emerald-400",children:[" ","terminar\xe1s el mes con un super\xe1vit de ",(0,r.xG)(E-A),"."]})]}),(0,a.jsxs)("p",{className:"text-slate-500 text-sm mt-2",children:["Quedan ",L," d\xedas en el mes"]})]})]})})]}),e&&(0,a.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,a.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:Y}),(0,a.jsx)("div",{className:"relative bg-slate-900 border border-slate-700 rounded-xl shadow-2xl w-full max-w-md max-h-[90vh] overflow-y-auto",children:(0,a.jsxs)("div",{className:"p-6",children:[(0,a.jsx)("h2",{className:"text-xl font-bold text-white mb-4",children:t?"Editar presupuesto":"Nuevo presupuesto"}),(0,a.jsx)(i,{onSubmit:_,onCancel:Y,initialData:t?k:void 0})]})})]})]}):(0,a.jsx)("div",{className:"bg-slate-900 min-h-screen p-6",children:(0,a.jsxs)("div",{className:"max-w-4xl mx-auto",children:[(0,a.jsx)("div",{className:"flex items-center justify-between mb-6",children:(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Presupuesto Mensual"}),(0,a.jsxs)("p",{className:"text-slate-400 text-sm mt-1",children:[(0,r.ZY)(N)," ",y]})]})}),(0,a.jsxs)("div",{className:"text-center py-16 bg-slate-800/50 border border-slate-700/50 rounded-lg",children:[(0,a.jsx)(j.Z,{className:"w-12 h-12 text-slate-600 mx-auto mb-4"}),(0,a.jsx)("h3",{className:"text-lg font-medium text-slate-300",children:"No hay presupuesto para este mes"}),(0,a.jsx)("p",{className:"text-slate-500 mt-2 mb-6",children:"Crea un presupuesto para comenzar a gestionar tus finanzas"}),(0,a.jsxs)("button",{onClick:()=>{l(!1),s(!0)},className:(0,r.cn)("inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg font-medium","hover:bg-blue-500 transition-colors"),children:[(0,a.jsx)(f.Z,{className:"w-4 h-4"}),"Crear presupuesto"]})]}),e&&(0,a.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,a.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:Y}),(0,a.jsx)("div",{className:"relative bg-slate-900 border border-slate-700 rounded-xl shadow-2xl w-full max-w-md max-h-[90vh] overflow-y-auto",children:(0,a.jsxs)("div",{className:"p-6",children:[(0,a.jsx)("h2",{className:"text-xl font-bold text-white mb-4",children:"Nuevo presupuesto"}),(0,a.jsx)(i,{onSubmit:_,onCancel:Y})]})})]})]})})}var y=t(9294),w=t(3263);function k(){let{isOpen:e,close:s,toggle:t}=(0,y.A)(),{unreadCount:n}=(0,w.Z7)();return(0,a.jsxs)("div",{className:"flex min-h-screen bg-slate-950",children:[(0,a.jsx)(l.YE,{isOpen:e,onClose:s,unreadAlertsCount:n}),(0,a.jsxs)("div",{className:"flex-1 flex flex-col min-h-screen",children:[(0,a.jsx)(l.h4,{onMenuClick:t,title:"Presupuesto"}),(0,a.jsx)("main",{className:"flex-1 p-4 md:p-6 lg:p-8 pb-20",children:(0,a.jsx)(N,{})}),(0,a.jsx)(l.zM,{unreadAlertsCount:n})]})]})}},9397:function(e,s,t){"use strict";t.d(s,{Z:function(){return a}});let a=(0,t(8755).Z)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},3085:function(e,s,t){"use strict";t.d(s,{Z:function(){return a}});let a=(0,t(8755).Z)("trending-down",[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]])},525:function(e,s,t){"use strict";t.d(s,{Z:function(){return a}});let a=(0,t(8755).Z)("trending-up",[["path",{d:"M16 7h6v6",key:"box55l"}],["path",{d:"m22 7-8.5 8.5-5-5L2 17",key:"1t1m79"}]])}},function(e){e.O(0,[697,71,796,489,971,117,744],function(){return e(e.s=2257)}),_N_E=e.O()}]);