import { ContributionInput } from "@/components/ContributionInput"; import type { Profile } from "@/components/ProfileForm"; import { countryOf, type Country } from "@/lib/countries"; import { getUser, today } from "@/lib/data"; import { money, money0, ymd } from "@/lib/format"; import { contributionRoom, type Room } from "@/lib/invest"; // Employer rules that are one plain line. NZ: ird.govt.nz/kiwisaver-changes; UK: gov.uk/workplace-pensions (checked 2026-10-22). const AT_WORK: Record = { nz: "At work, your employer must add 3.5% of your pay to KiwiSaver when you contribute.", uk: "At work, your employer must pay at least 3% into your workplace pension (8% in total with yours) on earnings between £6,240 and £50,270.", }; // This tax year's contributions to tax-advantaged accounts against the limits for the user's country. export async function Contributions({ profile }: { profile: Profile & { country?: string } }) { const { supabase, user } = await getUser(); const country = countryOf(profile.country); const rows = await contributionRoom(supabase, profile, { tax: country.tax, today: ymd(await today()), locale: country.locale, mine: user?.user_metadata?.contributed }); return ; } export function ContributionsCard({ rows, profile, country }: { rows: Room[]; profile: Profile; country: Country }) { if (!rows.length) return null; const us = country.tax === "us"; // Limits are set in the country's own currency. $1,042.86 keeps its cents, $20,000 shows none. const m = (n: number) => (Math.round(n * 100) % 100 ? money : money0)(n, country.currency); const noHsa = us && profile.health && !profile.health.startsWith("High-deductible"); return (
{us ? "Contributions this year" : "Contributions this tax year"}
{rows.map((r) => { const both = r.contributed != null && r.limit != null; return (
{r.label}{!us && {r.year}} {both ? `${m(r.contributed!)} of ${m(r.limit!)}` : r.contributed != null ? `${m(r.contributed)} put in` : r.limit != null ? `${r.goal ? "Target" : "Limit"} ${m(r.limit)}` : ""}
{both && (
)} {r.left != null && (

{r.goal ? r.left > 0 ? <>Put in {m(r.left)} more by {r.deadline} to get the full government contribution. : "You'll get the full government contribution this year." : r.left > 0 ? <>You have {m(r.left)} of {r.label} room left {r.kind === "k401" ? `through payroll by ${r.deadline}` : `before ${r.deadline}`}. : r.left < 0 ? You're {m(-r.left)} over the {r.year} limit.{us ? " Ask your provider to return the extra." : ""} : `You've maxed your ${r.label} for ${r.year}.`}

)} {(r.note || (r.kind === "hsa" && noHsa)) && (

{[r.note, r.kind === "hsa" && noHsa ? "your health plan may not allow HSA contributions" : ""].filter(Boolean).join(". ")}

)} {r.from !== "linked" && }
); })} {AT_WORK[country.tax] &&

{AT_WORK[country.tax]}

}

{us ? "Counts deposits Plaid marks as contributions. A 401(k) employer match shows here too but doesn't count toward your limit." : `Counts deposits into linked accounts with ${rows.map((r) => r.label.split(" ")[0]).join(" or ").replace("Pension", "pension")} in the name, or what you add. Limits checked on government sites on 22 October 2026.`}

); }