"use client"; import type { ReactNode } from "react"; import { EVENT_TYPE_STYLES } from "@/components/calendario/day-cell"; import type { CalendarDay, CalendarEvent } from "@/components/calendario/types"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { friendlyDate, parseLocalDateString } from "@/lib/utils/date"; import { cn } from "@/lib/utils/ui"; import MoneyValues from "../money-values"; import { Badge } from "../ui/badge"; import { Card } from "../ui/card"; 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.lancamento.transactionType === "Receita"; const isPagamentoFatura = event.lancamento.name.startsWith("Pagamento fatura -"); return ( {event.lancamento.name} {event.lancamento.condition} {event.lancamento.paymentMethod} {event.lancamento.categoriaName} ); }; const renderBoleto = (event: Extract) => { const isPaid = Boolean(event.lancamento.isSettled); const dueDate = event.lancamento.dueDate; const formattedDueDate = dueDate ? new Intl.DateTimeFormat("pt-BR").format(new Date(dueDate)) : null; return ( {event.lancamento.name} {formattedDueDate && ( Vence em {formattedDueDate} )} {isPaid ? "Pago" : "Pendente"} ); }; const renderCard = (event: Extract) => ( Vencimento Fatura - {event.card.name} {event.card.status ?? "Fatura"} {event.card.totalDue !== null ? ( ) : null} ); const renderEvent = (event: CalendarEvent) => { switch (event.type) { case "lancamento": return renderLancamento(event); case "boleto": return renderBoleto(event); case "cartao": 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. )} Cancelar Novo lançamento ); }