import Link from "next/link"; import { Badge } from "@/components/ui/badge"; import { tr } from "@/i18n/tr"; import { cn } from "@/lib/utils"; import { formatMoney } from "@/shared/format"; import { formatAssetQuantity } from "@/shared/assets"; import type { AssetsReport, ContactsReport } from "../extra"; import { dayLabel } from "./report-frame"; const signed = (n: number) => `${n > 0 ? "+" : n < 0 ? "−" : ""}${formatMoney(Math.abs(n))}`; const bp = (n: number | null) => n === null ? "" : ` (${n < 0 ? "−" : "+"}%${(Math.abs(n) / 100).toLocaleString("tr-TR", { maximumFractionDigits: 1 })})`; function Stat({ label, value, tone }: { label: string; value: string; tone?: string }) { return (

{label}

{value}

); } export function ContactsReportView({ data }: { data: ContactsReport }) { const t = tr.reports.contacts; return (

{t.contact}

{data.contacts.length ? (
{data.contacts.map((c) => ( ))}
{t.contact} {t.direction} {t.balance} {t.due}
{c.name} {c.balanceMinor > 0 ? t.owesMe : t.iOwe} 0 ? "text-income" : "text-expense", )} > {formatMoney(Math.abs(c.balanceMinor))} {c.dueDate ? dayLabel(c.dueDate) : "—"} {t.dueStates[c.due] ? ( {t.dueStates[c.due]} ) : null}
) : (

{t.noContacts}

)}

{t.inKindTitle}

{t.inKindHint}

{data.inKind.length ? (
{data.inKind.map((d) => ( ))}
{t.contact} {t.direction} {t.remaining} {t.value} {t.since}
{d.contactName} {d.direction === "receivable" ? t.receivable : t.debt} {d.remainingLabel} {d.valueMinor === null ? "—" : formatMoney(d.valueMinor)} {dayLabel(d.date)}
) : (

{t.noInKind}

)} {data.inKindTotals.unpriced ? (

{t.unpriced(data.inKindTotals.unpriced)}

) : null}
); } export function AssetsReportView({ data }: { data: AssetsReport }) { const t = tr.reports.assets; const p = data.period; const tone = (n: number | null) => n === null ? "" : n < 0 ? "text-expense" : n > 0 ? "text-income" : ""; return (

{t.periodTitle}: {dayLabel(p.from)} – {dayLabel(p.to)}

{p.excluded ? (

{t.excluded(p.excluded)}

) : null}
{data.items.length ? (
{data.items.map((a) => ( ))}
{t.asset} {t.quantity} {t.cost} {t.value} {t.unrealized} {t.realized}
{a.name || a.label} {formatAssetQuantity(a.assetKey, a.summary.quantity)} {formatMoney(a.summary.costMinor)} {a.summary.currentValueMinor === null ? t.noPrice : formatMoney(a.summary.currentValueMinor)} {a.summary.unrealizedMinor === null ? "—" : `${signed(a.summary.unrealizedMinor)}${bp(a.summary.unrealizedBp)}`} {signed(a.summary.realizedMinor)}
{t.total} {formatMoney(data.totals.costMinor)} {formatMoney(data.totals.valueMinor)} {signed(data.totals.unrealizedMinor)} {signed(data.totals.realizedMinor)}
) : (

{t.empty}

)}
); }