import React from 'react'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { CoinsData, HabitsData, WishlistData, UserData, User, CoinTransaction } from '@/lib/types'; import { t2d } from '@/lib/utils'; import Link from 'next/link'; import { DropdownMenuItem } from '@/components/ui/dropdown-menu'; import { Info } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from '@/components/ui/tooltip'; interface NotificationDropdownProps { currentUser: User | null; unreadNotifications: CoinTransaction[]; displayedReadNotifications: CoinTransaction[]; habitsData: HabitsData; wishlistData: WishlistData; usersData: UserData; } // Helper function to get the name of the related item const getRelatedItemName = (tx: CoinTransaction, habitsData: HabitsData, wishlistData: WishlistData): string | undefined => { if (!tx.relatedItemId) return undefined; if (tx.type === 'HABIT_COMPLETION' || tx.type === 'TASK_COMPLETION') { return habitsData.habits.find(h => h.id === tx.relatedItemId)?.name; } if (tx.type === 'WISH_REDEMPTION') { return wishlistData.items.find(w => w.id === tx.relatedItemId)?.name; } return undefined; }; export default function NotificationDropdown({ currentUser, unreadNotifications, // Use props directly displayedReadNotifications, // Use props directly habitsData, wishlistData, usersData, }: NotificationDropdownProps) { const t = useTranslations('NotificationDropdown'); // Helper function to generate notification message, now using t const getNotificationMessage = (tx: CoinTransaction, triggeringUser?: User, relatedItemName?: string): string => { const username = triggeringUser?.username || t('defaultUsername'); const itemName = relatedItemName || t('defaultItemName'); switch (tx.type) { case 'HABIT_COMPLETION': case 'TASK_COMPLETION': return t('userCompletedItem', { username, itemName }); case 'WISH_REDEMPTION': return t('userRedeemedItem', { username, itemName }); default: return t('activityRelatedToItem', { username, itemName }); } }; if (!currentUser) { return
{message}
{timeAgo}
{t('notificationsTooltip')}