import { Currency } from '@repo/ui/components/currency' import { Button } from '@repo/ui/components/ui/button' import { Separator } from '@repo/ui/components/ui/separator' import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from '@repo/ui/components/ui/table' import { useWizard } from '@/components/wizard' import { applyDiscount } from './discount' type ReviewProps = { state: any } export function Review({ state }: ReviewProps) { const wizard = useWizard() const { coupon, items } = state || { items: [], coupon: {} } const subtotal = items?.reduce( (acc, { course, quantity }) => acc + (course?.unit_price || 0) * (Number.isFinite(quantity) && quantity > 0 ? quantity : 1), 0 ) || 0 const discount = coupon ? applyDiscount(subtotal, coupon.amount, coupon.type) * -1 : 0 const total = subtotal > 0 ? subtotal + discount : 0 return ( <> Curso Quantidade Valor unit. Total {items?.map(({ course, quantity }, index) => { return ( {course.name} {quantity} {course.unit_price} {course.unit_price * quantity} ) })} Subtotal {subtotal} Descontos {discount} Total {total}
) }