"use client"; import { RiAlertFill, RiArrowRightLine, RiBankCardLine, RiBarChart2Line, RiCheckboxCircleFill, RiErrorWarningLine, RiFileListLine, RiInboxLine, RiNotification3Line, RiTimeLine, } from "@remixicon/react"; import Link from "next/link"; import { useState } from "react"; import { Badge } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Empty, EmptyDescription, EmptyMedia, EmptyTitle, } from "@/components/ui/empty"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import type { BudgetNotification, DashboardNotification, } from "@/lib/dashboard/notifications"; import { cn } from "@/lib/utils/ui"; type NotificationBellProps = { notifications: DashboardNotification[]; totalCount: number; budgetNotifications: BudgetNotification[]; preLancamentosCount?: number; }; function formatDate(dateString: string): string { const [year, month, day] = dateString.split("-").map(Number); const date = new Date(Date.UTC(year, month - 1, day)); return date.toLocaleDateString("pt-BR", { day: "2-digit", month: "short", timeZone: "UTC", }); } function formatCurrency(amount: number): string { return new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL", }).format(amount); } function SectionLabel({ icon, title, }: { icon: React.ReactNode; title: string; }) { return (
{icon} {title}
); } export function NotificationBell({ notifications, totalCount, budgetNotifications, preLancamentosCount = 0, }: NotificationBellProps) { const [open, setOpen] = useState(false); const effectiveTotalCount = totalCount + preLancamentosCount + budgetNotifications.length; const displayCount = effectiveTotalCount > 99 ? "99+" : effectiveTotalCount.toString(); const hasNotifications = effectiveTotalCount > 0; const invoiceNotifications = notifications.filter( (n) => n.type === "invoice", ); const boletoNotifications = notifications.filter((n) => n.type === "boleto"); return ( Notificações {/* Header */} Notificações {hasNotifications && ( {effectiveTotalCount}{" "} {effectiveTotalCount === 1 ? "item" : "itens"} )} {!hasNotifications ? (
Nenhuma notificação Você está em dia com seus pagamentos!
) : (
{/* Pré-lançamentos */} {preLancamentosCount > 0 && (
} title="Pré-lançamentos" /> setOpen(false)} className="group mx-1 mb-1 flex items-center gap-2 rounded-md px-2 py-2 transition-colors hover:bg-accent/60" >

{preLancamentosCount === 1 ? "1 pré-lançamento aguardando revisão" : `${preLancamentosCount} pré-lançamentos aguardando revisão`}

)} {/* Orçamentos */} {budgetNotifications.length > 0 && (
} title="Orçamentos" />
{budgetNotifications.map((n) => (
{n.status === "exceeded" ? ( ) : ( )}

{n.status === "exceeded" ? ( <> Orçamento de {n.categoryName}{" "} excedido —{" "} {formatCurrency(n.spentAmount)} de{" "} {formatCurrency(n.budgetAmount)} ( {Math.round(n.usedPercentage)}%) ) : ( <> {n.categoryName} atingiu{" "} {Math.round(n.usedPercentage)}% do orçamento —{" "} {formatCurrency(n.spentAmount)} de{" "} {formatCurrency(n.budgetAmount)} )}

))}
)} {/* Cartão de Crédito */} {invoiceNotifications.length > 0 && (
} title="Cartão de Crédito" />
{invoiceNotifications.map((n) => (
{n.status === "overdue" ? ( ) : ( )}

{n.status === "overdue" ? ( <> A fatura de {n.name} venceu em{" "} {formatDate(n.dueDate)} {n.showAmount && n.amount > 0 && ( <> {" "} — {formatCurrency(n.amount)} )} ) : ( <> A fatura de {n.name} vence em{" "} {formatDate(n.dueDate)} {n.showAmount && n.amount > 0 && ( <> {" "} — {formatCurrency(n.amount)} )} )}

))}
)} {/* Boletos */} {boletoNotifications.length > 0 && (
} title="Boletos" />
{boletoNotifications.map((n) => (
{n.status === "overdue" ? ( ) : ( )}

{n.status === "overdue" ? ( <> O boleto {n.name} {n.amount > 0 && ( <> {" "} — {formatCurrency(n.amount)} )}{" "} venceu em {formatDate(n.dueDate)} ) : ( <> O boleto {n.name} {n.amount > 0 && ( <> {" "} — {formatCurrency(n.amount)} )}{" "} vence em {formatDate(n.dueDate)} )}

))}
)}
)}
); }