import { Minus, RefreshCw, TrendingDown, TrendingUp } from "lucide-react"; import { RelativeTime } from "@/lib/time"; import type { Quote } from "@/lib/api"; import { useQuotes, useFetchQuotes, useMonthlyPayedTotal } from "@/lib/queries"; import { useNavigate } from "@tanstack/react-router"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; const priceFormatter = new Intl.NumberFormat("es-AR", { minimumFractionDigits: 2, maximumFractionDigits: 2, }); function QuoteCard({ quote, title, to, variant }: { quote: Quote | undefined; title: string; to?: string; variant?: "default" | "minimal" }) { const navigate = useNavigate(); const diff = quote ? Number(quote.difference) : 0; const pct = quote ? Number(quote.percentage) : 0; const isUp = diff > 0; const isDown = diff < 0; return (
to && navigate({ to })} onKeyDown={(e) => { if (e.key === "Enter" && to) navigate({ to }); }} role={to ? "button" : undefined} tabIndex={to ? 0 : undefined} >

{title}

{quote && ( {isUp ? ( ) : isDown ? ( ) : ( )}

{isUp ? `Subió $${priceFormatter.format(diff)} (${pct.toFixed(2)}%)` : isDown ? `Bajó $${priceFormatter.format(Math.abs(diff))} (${pct.toFixed(2)}%)` : "Sin cambios"}

)}
{quote && ( )}
{quote ? ( variant === "minimal" ? (

${priceFormatter.format(Number(quote.buy))}

Compra: ${priceFormatter.format(Number(quote.buy))}

Venta: ${priceFormatter.format(Number(quote.sell))}

) : (

Compra: ${priceFormatter.format(Number(quote.buy))}

Venta: ${priceFormatter.format(Number(quote.sell))}

) ) : (

Sin datos

)}
); } export function DashboardPage() { const { data: quotes, isLoading } = useQuotes(); const { mutate: doFetchQuotes, isPending } = useFetchQuotes(); const belo = quotes?.find((q) => q.type === "BELO"); const blue = quotes?.find((q) => q.type === "BLUE"); const now = new Date(); const { data: monthlyExpenses } = useMonthlyPayedTotal(now.getFullYear(), now.getMonth() + 1); const isFetching = isLoading || isPending; return (

Panel

Total ingresos

$0.00

Gastos del mes

${priceFormatter.format(monthlyExpenses?.total ?? 0)}

); }