Files
finanzas/dist/_next/static/chunks/app/debts/page-28aedff94a342b70.js

1 line
17 KiB
JavaScript

(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[273],{2799:function(e,t,a){Promise.resolve().then(a.bind(a,9220))},9220:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return k}});var s=a(7437),l=a(553),r=a(4508),n=a(401),o=a(5675),i=a(8930);let d={housing:"bg-blue-500/20 text-blue-400 border-blue-500/30",services:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",subscription:"bg-purple-500/20 text-purple-400 border-purple-500/30",other:"bg-gray-500/20 text-gray-400 border-gray-500/30"},c={shopping:"bg-pink-500/20 text-pink-400 border-pink-500/30",food:"bg-orange-500/20 text-orange-400 border-orange-500/30",entertainment:"bg-indigo-500/20 text-indigo-400 border-indigo-500/30",health:"bg-red-500/20 text-red-400 border-red-500/30",transport:"bg-cyan-500/20 text-cyan-400 border-cyan-500/30",other:"bg-gray-500/20 text-gray-400 border-gray-500/30"},u={housing:"Vivienda",services:"Servicios",subscription:"Suscripci\xf3n",shopping:"Compras",food:"Comida",entertainment:"Entretenimiento",health:"Salud",transport:"Transporte",other:"Otro"};function m(e){let{debt:t,type:a,onTogglePaid:l,onEdit:m,onDelete:x}=e,b="fixed"===a,h=b?d:c,g=h[t.category]||h.other;return(0,s.jsx)("div",{className:(0,r.cn)("group relative bg-slate-800 border border-slate-700/50 rounded-lg p-4","transition-all duration-200 hover:border-slate-600",t.isPaid&&"opacity-60"),children:(0,s.jsxs)("div",{className:"flex items-start gap-3",children:[(0,s.jsx)("button",{onClick:l,className:(0,r.cn)("mt-1 w-5 h-5 rounded border-2 flex items-center justify-center","transition-colors duration-200",t.isPaid?"bg-emerald-500 border-emerald-500":"border-slate-500 hover:border-emerald-400"),"aria-label":t.isPaid?"Marcar como no pagada":"Marcar como pagada",children:t.isPaid&&(0,s.jsx)(n.Z,{className:"w-3 h-3 text-white"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{className:(0,r.cn)("text-white font-medium truncate",t.isPaid&&"line-through text-slate-400"),children:t.name}),(0,s.jsx)("p",{className:"text-slate-400 text-sm mt-0.5",children:b?"Vence d\xeda ".concat(t.dueDay):(0,r.iS)(t.date)})]}),(0,s.jsx)("span",{className:"font-mono text-emerald-400 font-semibold whitespace-nowrap",children:(0,r.xG)(t.amount)})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between mt-3",children:[(0,s.jsx)("span",{className:(0,r.cn)("inline-flex items-center px-2 py-0.5 rounded text-xs font-medium border",g),children:u[t.category]||t.category}),b&&t.isAutoDebit&&(0,s.jsx)("span",{className:"text-xs text-slate-500",children:"D\xe9bito autom\xe1tico"})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,s.jsx)("button",{onClick:m,className:"p-1.5 text-slate-400 hover:text-blue-400 hover:bg-blue-500/10 rounded transition-colors","aria-label":"Editar",children:(0,s.jsx)(o.Z,{className:"w-4 h-4"})}),(0,s.jsx)("button",{onClick:x,className:"p-1.5 text-slate-400 hover:text-red-400 hover:bg-red-500/10 rounded transition-colors","aria-label":"Eliminar",children:(0,s.jsx)(i.Z,{className:"w-4 h-4"})})]})]})})}var x=a(2265),b=a(4835);let h=[{value:"housing",label:"Vivienda"},{value:"services",label:"Servicios"},{value:"subscription",label:"Suscripci\xf3n"},{value:"other",label:"Otro"}];function g(e){let{initialData:t,onSubmit:a,onCancel:l}=e,[n,o]=(0,x.useState)({name:(null==t?void 0:t.name)||"",amount:(null==t?void 0:t.amount)||0,dueDay:(null==t?void 0:t.dueDay)||1,category:(null==t?void 0:t.category)||"other",isAutoDebit:(null==t?void 0:t.isAutoDebit)||!1,notes:(null==t?void 0:t.notes)||""}),[i,d]=(0,x.useState)({}),c=()=>{let e={};return n.name.trim()||(e.name="El nombre es requerido"),n.amount<=0&&(e.amount="El monto debe ser mayor a 0"),(n.dueDay<1||n.dueDay>31)&&(e.dueDay="El d\xeda debe estar entre 1 y 31"),d(e),0===Object.keys(e).length},u=(e,t)=>{o(a=>({...a,[e]:t})),i[e]&&d(t=>{let a={...t};return delete a[e],a})};return(0,s.jsxs)("form",{onSubmit:e=>{e.preventDefault(),c()&&a(n)},className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"name",className:"block text-sm font-medium text-slate-300 mb-1",children:["Nombre ",(0,s.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,s.jsx)("input",{type:"text",id:"name",value:n.name,onChange:e=>u("name",e.target.value),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",i.name?"border-red-500":"border-slate-600"),placeholder:"Ej: Alquiler, Internet, etc."}),i.name&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-400",children:i.name})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"amount",className:"block text-sm font-medium text-slate-300 mb-1",children:["Monto ",(0,s.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,s.jsx)("input",{type:"number",id:"amount",min:"0",step:"0.01",value:n.amount||"",onChange:e=>u("amount",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",i.amount?"border-red-500":"border-slate-600"),placeholder:"0.00"}),i.amount&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-400",children:i.amount})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"dueDay",className:"block text-sm font-medium text-slate-300 mb-1",children:["D\xeda de vencimiento ",(0,s.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,s.jsx)("input",{type:"number",id:"dueDay",min:"1",max:"31",value:n.dueDay,onChange:e=>u("dueDay",parseInt(e.target.value)||1),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",i.dueDay?"border-red-500":"border-slate-600"),placeholder:"1"}),i.dueDay&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-400",children:i.dueDay})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"category",className:"block text-sm font-medium text-slate-300 mb-1",children:"Categor\xeda"}),(0,s.jsx)("select",{id:"category",value:n.category,onChange:e=>u("category",e.target.value),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border border-slate-600 rounded-lg text-white","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500"),children:h.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("input",{type:"checkbox",id:"isAutoDebit",checked:n.isAutoDebit,onChange:e=>u("isAutoDebit",e.target.checked),className:"w-4 h-4 rounded border-slate-600 bg-slate-800 text-blue-500 focus:ring-blue-500/50"}),(0,s.jsx)("label",{htmlFor:"isAutoDebit",className:"text-sm text-slate-300",children:"Tiene d\xe9bito autom\xe1tico"})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"notes",className:"block text-sm font-medium text-slate-300 mb-1",children:["Notas ",(0,s.jsx)("span",{className:"text-slate-500",children:"(opcional)"})]}),(0,s.jsx)("textarea",{id:"notes",rows:3,value:n.notes,onChange:e=>u("notes",e.target.value),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border border-slate-600 rounded-lg text-white placeholder-slate-500","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500","resize-none"),placeholder:"Notas adicionales..."})]}),(0,s.jsxs)("div",{className:"flex gap-3 pt-2",children:[(0,s.jsx)("button",{type:"button",onClick:l,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,s.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:(null==t?void 0:t.id)?"Guardar cambios":"Agregar deuda"})]})]})}let p=[{value:"shopping",label:"Compras"},{value:"food",label:"Comida"},{value:"entertainment",label:"Entretenimiento"},{value:"health",label:"Salud"},{value:"transport",label:"Transporte"},{value:"other",label:"Otro"}];function f(e){let{initialData:t,onSubmit:a,onCancel:l}=e,[n,o]=(0,x.useState)({name:(null==t?void 0:t.name)||"",amount:(null==t?void 0:t.amount)||0,date:(null==t?void 0:t.date)||new Date().toISOString().split("T")[0],category:(null==t?void 0:t.category)||"other",notes:(null==t?void 0:t.notes)||""}),[i,d]=(0,x.useState)({}),c=()=>{let e={};return n.name.trim()||(e.name="El nombre es requerido"),n.amount<=0&&(e.amount="El monto debe ser mayor a 0"),n.date||(e.date="La fecha es requerida"),d(e),0===Object.keys(e).length},u=(e,t)=>{o(a=>({...a,[e]:t})),i[e]&&d(t=>{let a={...t};return delete a[e],a})};return(0,s.jsxs)("form",{onSubmit:e=>{e.preventDefault(),c()&&a(n)},className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"name",className:"block text-sm font-medium text-slate-300 mb-1",children:["Nombre ",(0,s.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,s.jsx)("input",{type:"text",id:"name",value:n.name,onChange:e=>u("name",e.target.value),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",i.name?"border-red-500":"border-slate-600"),placeholder:"Ej: Supermercado, Cena, etc."}),i.name&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-400",children:i.name})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"amount",className:"block text-sm font-medium text-slate-300 mb-1",children:["Monto ",(0,s.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,s.jsx)("input",{type:"number",id:"amount",min:"0",step:"0.01",value:n.amount||"",onChange:e=>u("amount",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",i.amount?"border-red-500":"border-slate-600"),placeholder:"0.00"}),i.amount&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-400",children:i.amount})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"date",className:"block text-sm font-medium text-slate-300 mb-1",children:["Fecha ",(0,s.jsx)("span",{className:"text-red-400",children:"*"})]}),(0,s.jsx)("input",{type:"date",id:"date",value:n.date,onChange:e=>u("date",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",i.date?"border-red-500":"border-slate-600")}),i.date&&(0,s.jsx)("p",{className:"mt-1 text-sm text-red-400",children:i.date})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{htmlFor:"category",className:"block text-sm font-medium text-slate-300 mb-1",children:"Categor\xeda"}),(0,s.jsx)("select",{id:"category",value:n.category,onChange:e=>u("category",e.target.value),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border border-slate-600 rounded-lg text-white","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500"),children:p.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{htmlFor:"notes",className:"block text-sm font-medium text-slate-300 mb-1",children:["Notas ",(0,s.jsx)("span",{className:"text-slate-500",children:"(opcional)"})]}),(0,s.jsx)("textarea",{id:"notes",rows:3,value:n.notes,onChange:e=>u("notes",e.target.value),className:(0,r.cn)("w-full px-3 py-2 bg-slate-800 border border-slate-600 rounded-lg text-white placeholder-slate-500","focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:border-blue-500","resize-none"),placeholder:"Notas adicionales..."})]}),(0,s.jsxs)("div",{className:"flex gap-3 pt-2",children:[(0,s.jsx)("button",{type:"button",onClick:l,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,s.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:(null==t?void 0:t.id)?"Guardar cambios":"Agregar deuda"})]})]})}var v=a(9397),j=a(1804);function N(){let[e,t]=(0,x.useState)("fixed"),[a,l]=(0,x.useState)(!1),[n,o]=(0,x.useState)(null),{fixedDebts:i,variableDebts:d,addFixedDebt:c,updateFixedDebt:u,deleteFixedDebt:h,toggleFixedDebtPaid:p,addVariableDebt:N,updateVariableDebt:y,deleteVariableDebt:w,toggleVariableDebtPaid:k}=(0,b.J)(),C="fixed"===e?i:d,D="fixed"===e?(0,r.zF)(i):(0,r.Q0)(d),S=e=>{o(e),l(!0)},E=()=>{l(!1),o(null)},F=t=>{confirm("\xbfEst\xe1s seguro de que deseas eliminar esta deuda?")&&("fixed"===e?h(t.id):w(t.id))},A=t=>{"fixed"===e?p(t.id):k(t.id)},P=C.filter(e=>e.isPaid).length,Z=C.filter(e=>!e.isPaid).length;return(0,s.jsxs)("div",{className:"bg-slate-900 min-h-screen p-6",children:[(0,s.jsxs)("div",{className:"max-w-4xl mx-auto",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Deudas"}),(0,s.jsx)("p",{className:"text-slate-400 text-sm mt-1",children:"Gestiona tus gastos fijos y variables"})]}),(0,s.jsxs)("button",{onClick:()=>{o(null),l(!0)},className:(0,r.cn)("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,s.jsx)(v.Z,{className:"w-4 h-4"}),"Agregar"]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-3 gap-4 mb-6",children:[(0,s.jsxs)("div",{className:"bg-slate-800 border border-slate-700/50 rounded-lg p-4",children:[(0,s.jsx)("p",{className:"text-slate-400 text-sm",children:"Total pendiente"}),(0,s.jsx)("p",{className:"text-xl font-mono font-semibold text-emerald-400 mt-1",children:(0,r.xG)(D)})]}),(0,s.jsxs)("div",{className:"bg-slate-800 border border-slate-700/50 rounded-lg p-4",children:[(0,s.jsx)("p",{className:"text-slate-400 text-sm",children:"Pagadas"}),(0,s.jsx)("p",{className:"text-xl font-semibold text-blue-400 mt-1",children:P})]}),(0,s.jsxs)("div",{className:"bg-slate-800 border border-slate-700/50 rounded-lg p-4",children:[(0,s.jsx)("p",{className:"text-slate-400 text-sm",children:"Pendientes"}),(0,s.jsx)("p",{className:"text-xl font-semibold text-orange-400 mt-1",children:Z})]})]}),(0,s.jsxs)("div",{className:"flex gap-2 mb-6",children:[(0,s.jsxs)("button",{onClick:()=>t("fixed"),className:(0,r.cn)("px-4 py-2 rounded-lg font-medium transition-colors","fixed"===e?"bg-blue-600 text-white":"bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-white"),children:["Fijas (",i.length,")"]}),(0,s.jsxs)("button",{onClick:()=>t("variable"),className:(0,r.cn)("px-4 py-2 rounded-lg font-medium transition-colors","variable"===e?"bg-blue-600 text-white":"bg-slate-800 text-slate-400 hover:bg-slate-700 hover:text-white"),children:["Variables (",d.length,")"]})]}),(0,s.jsx)("div",{className:"space-y-3",children:0===C.length?(0,s.jsxs)("div",{className:"text-center py-16 bg-slate-800/50 border border-slate-700/50 rounded-lg",children:[(0,s.jsx)(j.Z,{className:"w-12 h-12 text-slate-600 mx-auto mb-4"}),(0,s.jsxs)("h3",{className:"text-lg font-medium text-slate-300",children:["No hay deudas ","fixed"===e?"fijas":"variables"]}),(0,s.jsx)("p",{className:"text-slate-500 mt-2",children:'Haz clic en "Agregar" para crear una nueva deuda'})]}):C.map(t=>(0,s.jsx)(m,{debt:t,type:e,onTogglePaid:()=>A(t),onEdit:()=>S(t),onDelete:()=>F(t)},t.id))})]}),a&&(0,s.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[(0,s.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:E}),(0,s.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,s.jsxs)("div",{className:"p-6",children:[(0,s.jsx)("h2",{className:"text-xl font-bold text-white mb-4",children:n?"Editar deuda":"fixed"===e?"Nueva deuda fija":"Nueva deuda variable"}),"fixed"===e?(0,s.jsx)(g,{initialData:n,onSubmit:e=>{(null==n?void 0:n.id)?u(n.id,e):c({...e,isPaid:!1}),E()},onCancel:E}):(0,s.jsx)(f,{initialData:n,onSubmit:e=>{(null==n?void 0:n.id)?y(n.id,e):N({...e,isPaid:!1}),E()},onCancel:E})]})})]})]})}var y=a(9294),w=a(3263);function k(){let{isOpen:e,close:t,open:a}=(0,y.A)(),{unreadCount:r}=(0,w.Z7)();return(0,s.jsxs)("div",{className:"min-h-screen bg-slate-950",children:[(0,s.jsx)(l.YE,{isOpen:e,onClose:t,unreadAlertsCount:r}),(0,s.jsxs)("div",{className:"lg:ml-64 min-h-screen flex flex-col",children:[(0,s.jsx)(l.h4,{onMenuClick:a,title:"Deudas"}),(0,s.jsx)("main",{className:"flex-1 p-4 md:p-6 lg:p-8 pb-20 lg:pb-8",children:(0,s.jsx)(N,{})})]}),(0,s.jsx)(l.zM,{unreadAlertsCount:r})]})}},5675:function(e,t,a){"use strict";a.d(t,{Z:function(){return s}});let s=(0,a(8755).Z)("pencil",[["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"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]])},9397:function(e,t,a){"use strict";a.d(t,{Z:function(){return s}});let s=(0,a(8755).Z)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])}},function(e){e.O(0,[697,71,796,489,971,117,744],function(){return e(e.s=2799)}),_N_E=e.O()}]);