'use client'; import { formatPrice } from 'brainerce'; import { useTranslations } from '@/core/lib/translations'; import { useCart, useRegion } from '@/core/providers/store-provider'; import { TaxEstimateLine } from '@/ui/cart/tax-estimate-line'; import { useCurrency } from '@/core/lib/use-currency'; import { Separator } from '@/components/ui/separator'; import { cn } from '@/core/lib/utils'; interface CartSummaryProps { className?: string; } export function CartSummary({ className }: CartSummaryProps) { const t = useTranslations('cart'); const tc = useTranslations('common'); const { totals, cart } = useCart(); const currency = useCurrency(); const { region } = useRegion(); // The cart is priced in the store currency, whatever region the shopper browses in: only the checkout knows // what the region will charge. When the shopper sees another currency on the product pages, say which one // the cart is in, without claiming what will be charged (a region may only display its currency). const regionCurrency = region?.currency?.toUpperCase(); const cartInOtherCurrency = !!regionCurrency && regionCurrency !== currency.toUpperCase(); const rules = cart?.appliedDiscounts; const ruleAmt = cart?.ruleDiscountAmount ? parseFloat(cart.ruleDiscountAmount) : 0; const couponAmt = totals.discount - ruleAmt; return (
{t('currencyNote', { currency: currency.toUpperCase() })}
)}