"use client" import type { ReactNode } from "react" import { Separator } from "@/shared/components/ui/separator" import { cn } from "@/shared/lib/utils" import type { DocumentTotals } from "@/shared/hooks/use-document-totals" import { Money } from "@/shared/components/money" 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: ReactNode 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]) => ( } muted /> ))} {groupLabels && Object.keys(groupLabels).length > 0 && } {/* Subtotal */} } /> {/* Line-item discount */} {discountType === "line_item_level" && lineItemDiscount > 0 && ( } muted /> )} {/* Transaction-level discount */} {discountType === "transaction_level" && transactionDiscount > 0 && ( } muted /> )} {/* Tax */} {taxAmount > 0 && ( } muted /> )} {/* Total */}
Total
) }