"use client"; import { ArrowRightIcon } from "lucide-react"; import { ProvenanceBadge } from "@/components/inbox/provenance-badge"; import { previewDiff } from "@/lib/diff"; import { formatMoney, formatValue, humanize, isMoneyField } from "@/lib/format"; import { useI18n } from "@/lib/i18n"; import type { Provenance } from "@/lib/types"; import { cn } from "@/lib/utils"; function Value({ field, value, muted }: { field: string; value: unknown; muted?: boolean }) { const { locale } = useI18n(); return ( {formatValue(field, value, locale)} ); } /** Structured before → after of the tool's dry run: what will actually change. */ export function DiffView({ preview }: { preview: Record }) { const { t } = useI18n(); const { rows, details } = previewDiff(preview); if (!rows.length && !details.length) { return

{t("inbox.noPreview")}

; } return (
{rows.length > 0 && (
{rows.map((r) => ( ))}
{t("inbox.field")} {t("inbox.before")} {t("inbox.after")}
{humanize(r.field)} {r.hasBefore ? ( ) : ( — )}
)} {details.length > 0 && (
{details.map(([k, v]) => (
{humanize(k)}
))}
)}
); } /** The exact arguments the tool will run with, each with where it came from. */ export function ArgsTable({ args, provenance, }: { args: Record; provenance: Record; }) { const { t } = useI18n(); return (
{Object.entries(args).map(([k, v]) => ( ))}
{t("inbox.field")} {t("inbox.value")} {t("inbox.source")}
{k}
); } /** Live facts from the system of record (what the policy compared against). */ export function FactsList({ facts, args, }: { facts: Record; args: Record; }) { const { t, locale } = useI18n(); const entries = Object.entries(facts); if (!entries.length) return null; const amount = typeof args.amount === "number" ? args.amount : null; const total = typeof facts.order_total === "number" ? facts.order_total : null; return (

{t("inbox.facts")}

{amount !== null && total !== null && total > 0 && (

{t("inbox.totalOnOrder", { amount: formatMoney(amount, locale), total: formatMoney(total, locale), })}

total ? "bg-destructive" : "bg-primary")} style={{ width: `${Math.min(100, (amount / total) * 100)}%` }} />
)}
{entries.map(([k, v]) => (
{humanize(k)}
))}
); }