import { RiCalendarLine, RiLoader4Line, RiMoneyDollarCircleLine, } from "@remixicon/react"; import { formatInvoicePaymentDate, getInvoiceStatusBadgeVariant, type InvoiceDialogState, parseInvoiceDueDate, } from "@/features/dashboard/invoices/invoices-helpers"; import type { DashboardInvoice, InvoicePaymentAccountOption, } from "@/features/dashboard/invoices/invoices-queries"; import { AccountCardSelectContent } from "@/features/transactions/components/select-items"; import { PaymentSuccess } from "@/shared/components/feedback/payment-success"; import MoneyValues from "@/shared/components/money-values"; import { Badge } from "@/shared/components/ui/badge"; import { Button } from "@/shared/components/ui/button"; import { Card } from "@/shared/components/ui/card"; import { DatePicker } from "@/shared/components/ui/date-picker"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/shared/components/ui/dialog"; import { Label } from "@/shared/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/shared/components/ui/select"; import { Separator } from "@/shared/components/ui/separator"; import { INVOICE_PAYMENT_STATUS, INVOICE_STATUS_LABEL, } from "@/shared/lib/invoices"; import { InvoiceLogo } from "./invoice-logo"; type InvoicePaymentDialogProps = { invoice: DashboardInvoice | null; open: boolean; modalState: InvoiceDialogState; isPending: boolean; paymentAccountId: string; onPaymentAccountChange: (accountId: string) => void; paymentDate: Date; onPaymentDateChange: (date: Date) => void; paymentAccountOptions: InvoicePaymentAccountOption[]; onClose: () => void; onConfirm: () => void; }; export function InvoicePaymentDialog({ invoice, open, modalState, isPending, paymentAccountId, onPaymentAccountChange, paymentDate, onPaymentDateChange, paymentAccountOptions, onClose, onConfirm, }: InvoicePaymentDialogProps) { const isProcessing = modalState === "processing" || isPending; const paymentInfo = invoice ? formatInvoicePaymentDate(invoice.paidAt) : null; const dueInfo = invoice ? parseInvoiceDueDate(invoice.period, invoice.dueDay) : null; const isInvoicePending = invoice?.paymentStatus === INVOICE_PAYMENT_STATUS.PENDING; const paymentDateValue = paymentDate.toISOString().split("T")[0] ?? ""; const selectedAccount = paymentAccountOptions.find( (option) => option.value === paymentAccountId, ); return ( { if (nextOpen || isProcessing) { return; } onClose(); }} > { if (isProcessing) { event.preventDefault(); } }} onPointerDownOutside={(event) => { if (isProcessing) { event.preventDefault(); } }} > {modalState === "success" ? ( ) : ( <>
Confirmar pagamento {isInvoicePending ? "Escolha a conta de origem e a data em que a fatura foi paga." : "Fatura do cartão"}
{invoice ? (

Cartão

{invoice.cardName}

Total da fatura
{invoice.paymentStatus === INVOICE_PAYMENT_STATUS.PAID ? "Pago em" : "Vencimento"}
{invoice.paymentStatus === INVOICE_PAYMENT_STATUS.PAID ? (paymentInfo?.label?.replace(/^Pago em\s*/u, "") ?? "—") : (dueInfo?.label?.replace(/^Vence (em|dia)\s*/u, "") ?? "—")}
{isInvoicePending ? (
{ if (value) { onPaymentDateChange(new Date(`${value}T00:00:00`)); } }} disabled={isProcessing} />
) : (
Status atual {INVOICE_STATUS_LABEL[invoice.paymentStatus]}
)}
) : null} )}
); }