"use client" import { Separator } from "@/shared/components/ui/separator" import { formatCurrency } from "@/shared/utils/formatters" import { cn } from "@/shared/lib/utils" import type { DocumentTotals } from "@/shared/hooks/use-document-totals" export type DocumentTotalsSummaryProps = { totals: DocumentTotals discountType?: string | null taxLabel?: string | null /** Override labels for line groups, keyed by group name */ groupLabels?: Record } function SummaryRow({ label, value, muted = false, className, }: { label: string value: string muted?: boolean className?: string }) { return (
{label} {value}
) } export function DocumentTotalsSummary({ totals, discountType, taxLabel, groupLabels, }: DocumentTotalsSummaryProps) { const { subTotal, lineItemDiscount, transactionDiscount, totalDiscount, taxAmount, total, hasLineItems, } = totals if (!hasLineItems) return null return (
{/* Group breakdowns */} {groupLabels && Object.entries(groupLabels).map(([label, amount]) => ( ))} {groupLabels && Object.keys(groupLabels).length > 0 && } {/* Subtotal */} {/* Line-item discount */} {discountType === "line_item_level" && lineItemDiscount > 0 && ( )} {/* Transaction-level discount */} {discountType === "transaction_level" && transactionDiscount > 0 && ( )} {/* Tax */} {taxAmount > 0 && ( )} {/* Total */}
Total {formatCurrency(total)}
) }