"use client"; import { RiCalendarCheckLine } from "@remixicon/react"; import { format } from "date-fns"; import { ptBR } from "date-fns/locale"; import type { ReactNode } from "react"; import type { InstallmentAnticipationListItem } from "@/features/transactions/hooks/use-installment-anticipations"; import MoneyValues from "@/shared/components/money-values"; import { Badge } from "@/shared/components/ui/badge"; import { Card, CardContent, CardHeader, CardTitle, } from "@/shared/components/ui/card"; import { displayPeriod } from "@/shared/utils/period"; interface AnticipationCardProps { anticipation: InstallmentAnticipationListItem; } export function AnticipationCard({ anticipation }: AnticipationCardProps) { const isSettled = anticipation.transaction?.isSettled === true; const totalAmount = Number(anticipation.totalAmount); const discount = Number(anticipation.discount); const finalAmount = totalAmount < 0 ? totalAmount + discount : totalAmount - discount; const hasDiscount = discount > 0; const formatDate = (date: string) => { return format(new Date(date), "dd 'de' MMMM 'de' yyyy", { locale: ptBR, }); }; return (
{anticipation.installmentCount}{" "} {anticipation.installmentCount === 1 ? "parcela antecipada" : "parcelas antecipadas"}
{formatDate(anticipation.anticipationDate)}
{displayPeriod(anticipation.anticipationPeriod)}
{hasDiscount ? "Valor Final" : "Valor Total"}
{hasDiscount ? ( - ) : (
)} {isSettled ? "Pago" : "Pendente"} {anticipation.payer ? ( {anticipation.payer.name} ) : (
)} {anticipation.category ? ( {anticipation.category.name} ) : null}
{anticipation.note ? (

Observação

{anticipation.note}

) : null}
); } function DetailItem({ label, children, valueClassName, }: { label: string; children: ReactNode; valueClassName?: string; }) { return (
{label}
{children}
); }