import { Link } from "@tanstack/react-router"; import { useUpdateSetting } from "../hooks/useSettings"; import { useTotals } from "../hooks/useTotals"; import { useWeightUnit } from "../hooks/useWeightUnit"; import { formatPrice, formatWeight, type WeightUnit } from "../lib/formatters"; import { LucideIcon } from "../lib/iconData"; const UNITS: WeightUnit[] = ["g", "oz", "lb", "kg"]; interface TotalsBarProps { title?: string; stats?: Array<{ label: string; value: string }>; linkTo?: string; } export function TotalsBar({ title = "GearBox", stats, linkTo, }: TotalsBarProps) { const { data } = useTotals(); const unit = useWeightUnit(); const updateSetting = useUpdateSetting(); // When no stats provided, use global totals (backward compatible) const displayStats = stats ?? (data?.global ? [ { label: "items", value: String(data.global.itemCount) }, { label: "total", value: formatWeight(data.global.totalWeight, unit), }, { label: "spent", value: formatPrice(data.global.totalCost) }, ] : [ { label: "items", value: "0" }, { label: "total", value: formatWeight(null, unit) }, { label: "spent", value: formatPrice(null) }, ]); const titleContent = ( {title} ); const titleElement = linkTo ? ( {titleContent} ) : (

{titleContent}

); // If stats prop is explicitly an empty array, show title only (dashboard mode) const showStats = stats === undefined || stats.length > 0; return (
{titleElement}
{UNITS.map((u) => ( ))}
{showStats && (
{displayStats.map((stat) => ( {stat.value} {" "} {stat.label} ))}
)}
); }