import{z as u,w as e,p as a}from"./index-DDBPimHe.js";import{u as h}from"./useSuspenseQuery-BKRXugiP.js";import{A as f,W as b}from"./AppShell-EiEJ9r2t.js";import{T as j}from"./trending-up-yQ5ZXCJO.js";import{c as v}from"./wrench-ep8n-Rsp.js";import"./package-DE0SpHx9.js";const N=[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]],g=v("trending-down",N);function A(){const{data:r}=h(u()),d=new Map;for(const s of r){const o=!!s.administracion_id,c=s.administracion_id||s.cliente_particular_id,p=s.administracion?.nombre??s.cliente_particular?.nombre??"—",m=d.get(c)??{key:c,tipo:o?"Consorcio":"Particular",nombre:p,saldo:0,ultimoMov:s.descripcion},x=Number(s.monto);m.saldo+=s.tipo==="debito"?x:-x,d.set(c,m)}const t=Array.from(d.values()).sort((s,o)=>o.saldo-s.saldo),i=t.filter(s=>s.saldo>0).reduce((s,o)=>s+o.saldo,0),n=Math.abs(t.filter(s=>s.saldo<0).reduce((s,o)=>s+o.saldo,0));return e.jsx(f,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-widest text-muted-foreground font-mono",children:"Finanzas"}),e.jsx("h1",{className:"text-3xl font-bold mt-1",children:"Cuentas Corrientes"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Saldos calculados a partir de los movimientos cargados"})]}),e.jsxs("div",{className:"grid md:grid-cols-3 gap-4",children:[e.jsx(l,{tone:"success",icon:j,label:"Por cobrar",value:a(i)}),e.jsx(l,{tone:"info",icon:g,label:"A favor cliente",value:a(n)}),e.jsx(l,{tone:"primary",icon:b,label:"Cuentas activas",value:String(t.length)})]}),e.jsx("div",{className:"bg-card border border-border rounded-xl shadow-card overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-xs uppercase tracking-wider text-muted-foreground border-b border-border",children:[e.jsx("th",{className:"px-4 py-3 font-medium",children:"Cliente"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Tipo"}),e.jsx("th",{className:"px-4 py-3 font-medium",children:"Último movimiento"}),e.jsx("th",{className:"px-4 py-3 font-medium text-right",children:"Saldo"})]})}),e.jsxs("tbody",{children:[t.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-4 py-12 text-center text-sm text-muted-foreground",children:"Sin movimientos cargados."})}),t.map(s=>e.jsxs("tr",{className:"border-b border-border last:border-0 hover:bg-muted/40",children:[e.jsx("td",{className:"px-4 py-3 font-medium",children:s.nombre}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:`text-xs px-2 py-0.5 rounded ${s.tipo==="Consorcio"?"bg-info/10 text-info":"bg-accent text-accent-foreground"}`,children:s.tipo})}),e.jsx("td",{className:"px-4 py-3 text-xs text-muted-foreground",children:s.ultimoMov}),e.jsx("td",{className:`px-4 py-3 text-right font-mono font-semibold ${s.saldo>0?"text-success":s.saldo<0?"text-destructive":"text-muted-foreground"}`,children:a(s.saldo)})]},s.key))]})]})}),e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-card overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border",children:[e.jsx("h2",{className:"font-display font-semibold",children:"Movimientos recientes"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Últimos 50 movimientos"})]}),e.jsx("div",{className:"divide-y divide-border",children:r.slice(0,10).map(s=>e.jsxs("div",{className:"px-5 py-3 flex items-center gap-3 text-sm",children:[e.jsx("div",{className:"font-mono text-xs text-muted-foreground w-24 shrink-0",children:s.fecha}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium truncate",children:s.descripcion}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.administracion?.nombre??s.cliente_particular?.nombre})]}),e.jsxs("div",{className:`font-mono font-semibold ${s.tipo==="debito"?"text-success":"text-destructive"}`,children:[s.tipo==="debito"?"+":"−"," ",a(Number(s.monto))]})]},s.id))})]})]})})}function l({tone:r,icon:d,label:t,value:i}){const n=r==="success"?"text-success":r==="info"?"text-info":"text-primary";return e.jsxs("div",{className:"bg-card border border-border rounded-xl shadow-card p-5",children:[e.jsxs("div",{className:`flex items-center gap-2 ${n}`,children:[e.jsx(d,{className:"size-4"})," ",e.jsx("span",{className:"text-xs uppercase tracking-wider font-mono",children:t})]}),e.jsx("div",{className:"font-display font-bold text-2xl mt-2",children:i})]})}export{A as component};
