import { RiCheckboxCircleFill, RiGroupLine } from "@remixicon/react"; import Link from "next/link"; import { PercentageChangeIndicator } from "@/features/dashboard/components/percentage-change-indicator"; import { buildInvoiceDetailsHref, buildInvoiceInitials, formatInvoicePaymentDate, formatInvoiceWidgetOverdueLabel, formatInvoiceWidgetPaymentDate, getInvoiceShareLabel, parseInvoiceDueDate, parseInvoiceWidgetDueDate, } from "@/features/dashboard/invoices/invoices-helpers"; import type { DashboardInvoice } from "@/features/dashboard/invoices/invoices-queries"; import MoneyValues from "@/shared/components/money-values"; import { Avatar, AvatarFallback, AvatarImage, } from "@/shared/components/ui/avatar"; import { Button } from "@/shared/components/ui/button"; import { HoverCard, HoverCardContent, HoverCardTrigger, } from "@/shared/components/ui/hover-card"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/shared/components/ui/tooltip"; import { INVOICE_PAYMENT_STATUS } from "@/shared/lib/invoices"; import { getAvatarSrc } from "@/shared/lib/payers/utils"; import { isDateOnlyPast } from "@/shared/utils/date"; import { InvoiceLogo } from "./invoice-logo"; type InvoiceListItemProps = { invoice: DashboardInvoice; onPay: (invoiceId: string) => void; }; export function InvoiceListItem({ invoice, onPay }: InvoiceListItemProps) { const dueInfo = parseInvoiceWidgetDueDate(invoice.period, invoice.dueDay); const absoluteDueInfo = parseInvoiceDueDate(invoice.period, invoice.dueDay); const isPaid = invoice.paymentStatus === INVOICE_PAYMENT_STATUS.PAID; const isOverdue = !isPaid && dueInfo.date !== null && isDateOnlyPast(dueInfo.date); const paymentInfo = formatInvoiceWidgetPaymentDate(invoice.paidAt); const absolutePaymentInfo = formatInvoicePaymentDate(invoice.paidAt); const breakdown = invoice.pagadorBreakdown ?? []; const hasBreakdown = breakdown.length > 0; const hasMultiplePayers = breakdown.length > 1; const detailHref = buildInvoiceDetailsHref(invoice.cardId, invoice.period); const overdueLabel = formatInvoiceWidgetOverdueLabel(dueInfo.date); const dueTooltipLabel = overdueLabel || dueInfo.label !== absoluteDueInfo.label ? absoluteDueInfo.label : null; const paymentTooltipLabel = paymentInfo?.label && paymentInfo.label !== absolutePaymentInfo?.label ? absolutePaymentInfo?.label : null; const linkNode = ( {invoice.cardName} ); return (
  • {hasBreakdown ? ( {linkNode}

    Distribuição por pessoa

      {breakdown.map((share, index) => (
    • {buildInvoiceInitials(share.pagadorName)}

      {share.pagadorName}

      {getInvoiceShareLabel( share.amount, Math.abs(invoice.totalAmount), )}

      {share.percentageChange !== null ? ( vs. mês ant. ) : null}
    • ))}
    ) : ( linkNode )} {hasMultiplePayers ? ( Ver distribuição por pessoa Ver distribuição por pessoa ) : null}
    {!isPaid ? ( dueTooltipLabel ? ( {overdueLabel ?? dueInfo.label} {dueTooltipLabel} ) : ( {overdueLabel ?? dueInfo.label} ) ) : null} {isPaid && paymentInfo ? ( paymentTooltipLabel ? ( {paymentInfo.label} {paymentTooltipLabel} ) : ( {paymentInfo.label} ) ) : null}
    {isPaid ? ( Pago ) : ( )}
  • ); }