"use client"; import { Bell, ExternalLink, MessageSquare, ShoppingCart, TrendingUp, } from "lucide-react"; import Link from "next/link"; import { useLocale } from "next-intl"; import { Button } from "@/components/ui/button"; // ScrollArea não disponível, usando div com overflow import { Separator } from "@/components/ui/separator"; interface Notification { notification_id: number; notification_type: string; title: string; message: string; is_read: boolean; related_id: number | null; created_at: string; } interface NotificationDropdownProps { notifications: Notification[]; onMarkAsRead: (notificationId: number) => Promise; onViewAll?: () => void; } function formatTimeAgo(date: Date): string { const seconds = Math.floor((Date.now() - date.getTime()) / 1000); if (seconds < 60) return "há alguns segundos"; const minutes = Math.floor(seconds / 60); if (minutes < 60) return `há ${minutes} ${minutes === 1 ? "minuto" : "minutos"}`; const hours = Math.floor(minutes / 60); if (hours < 24) return `há ${hours} ${hours === 1 ? "hora" : "horas"}`; const days = Math.floor(hours / 24); if (days < 30) return `há ${days} ${days === 1 ? "dia" : "dias"}`; const months = Math.floor(days / 30); if (months < 12) return `há ${months} ${months === 1 ? "mês" : "meses"}`; const years = Math.floor(months / 12); return `há ${years} ${years === 1 ? "ano" : "anos"}`; } function getNotificationIcon(type: string) { switch (type) { case "purchase": case "sale": return ; case "bid": return ; case "system": return ; default: return ; } } function getNotificationColor(type: string) { switch (type) { case "purchase": case "sale": return "bg-green-500"; case "bid": return "bg-blue-500"; case "system": return "bg-yellow-500"; default: return "bg-gray-500"; } } export function NotificationDropdown({ notifications, onMarkAsRead, onViewAll, }: NotificationDropdownProps) { const locale = useLocale(); const handleNotificationClick = async (notification: Notification) => { if (!notification.is_read) { await onMarkAsRead(notification.notification_id); } }; if (notifications.length === 0) { return (
Nenhuma notificação
); } return (

Notificações

{onViewAll && ( )}
{notifications.map((notification, index) => (
{index < notifications.length - 1 && ( )}
))}
); }