"use client"; import type { ReactNode } from "react"; import { EVENT_TYPE_STYLES } from "@/features/calendar/components/day-cell"; 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 { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/shared/components/ui/dialog"; import type { CalendarDay, CalendarEvent } from "@/shared/lib/types/calendar"; import { friendlyDate, parseLocalDateString } from "@/shared/utils/date"; import { formatFinancialDateLabel } from "@/shared/utils/financial-dates"; import { cn } from "@/shared/utils/ui"; type EventModalProps = { open: boolean; day: CalendarDay | null; onClose: () => void; onCreate: (date: string) => void; }; const EventCard = ({ children, type, isPagamentoFatura = false, }: { children: ReactNode; type: CalendarEvent["type"]; isPagamentoFatura?: boolean; }) => { const style = isPagamentoFatura ? { dot: "bg-success" } : EVENT_TYPE_STYLES[type]; return ( {children} ); }; const renderLancamento = ( event: Extract, ) => { const isReceita = event.transaction.transactionType === "Receita"; const isPagamentoFatura = event.transaction.name.startsWith("Pagamento fatura -"); return ( {event.transaction.name} {event.transaction.categoriaName} ); }; const renderBoleto = (event: Extract) => { const isPaid = Boolean(event.transaction.isSettled); const dueDate = event.transaction.dueDate; const dueDateLabel = formatFinancialDateLabel(dueDate, "Vence em", { day: "2-digit", month: "2-digit", year: "numeric", }); return ( {event.transaction.name} {dueDateLabel && ( {dueDateLabel} )} {isPaid ? "Pago" : "Pendente"} ); }; const renderCard = (event: Extract) => ( Vencimento Fatura - {event.card.name} {event.card.status ?? "Invoice"} {event.card.totalDue !== null ? ( ) : null} ); const renderEvent = (event: CalendarEvent) => { switch (event.type) { case "transaction": return renderLancamento(event); case "boleto": return renderBoleto(event); case "card": return renderCard(event); default: return null; } }; export function EventModal({ open, day, onClose, onCreate }: EventModalProps) { const formattedDate = !day ? "" : friendlyDate(parseLocalDateString(day.date)); const handleCreate = () => { if (!day) return; onClose(); onCreate(day.date); }; const description = day?.events.length ? "Confira os lançamentos e vencimentos cadastrados para este dia." : "Nenhum lançamento encontrado para este dia. Você pode criar um novo lançamento agora."; return ( (!value ? onClose() : null)}> {formattedDate} {description} {day?.events.length ? ( day.events.map((event) => ( {renderEvent(event)} )) ) : ( Nenhum lançamento ou vencimento registrado. Clique em{" "} Novo lançamento{" "} para começar. )} Novo lançamento ); }