import { WishlistItemType, User } from '@/lib/types' import { useAtom } from 'jotai' import { useTranslations } from 'next-intl' import { usersAtom, currentUserAtom } from '@/lib/atoms' import { Avatar, AvatarFallback, AvatarImage } from './ui/avatar' import { hasPermission } from '@/lib/utils' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card' import ReactMarkdown from 'react-markdown' import { Button } from '@/components/ui/button' import { Coins, Edit, Trash2, Gift, MoreVertical, Archive, ArchiveRestore } from 'lucide-react' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' interface WishlistItemProps { item: WishlistItemType onEdit: () => void onDelete: () => void onRedeem: () => void onArchive: () => void onUnarchive: () => void canRedeem: boolean isHighlighted?: boolean isRecentlyRedeemed?: boolean isArchived?: boolean } const renderUserAvatars = (item: WishlistItemType, currentUser: User | null, usersData: { users: User[] }) => { if (!item.userIds || item.userIds.length <= 1) return null; return (
{item.userIds?.filter((u) => u !== currentUser?.id).map(userId => { const user = usersData.users.find(u => u.id === userId) if (!user) return null return ( {user.username[0]} ) })}
); }; export default function WishlistItem({ item, onEdit, onDelete, onRedeem, onArchive, onUnarchive, canRedeem, isHighlighted, isRecentlyRedeemed }: WishlistItemProps) { const t = useTranslations('WishlistItem') const [currentUser] = useAtom(currentUserAtom) const canWrite = hasPermission(currentUser, 'wishlist', 'write') const canInteract = hasPermission(currentUser, 'wishlist', 'interact') const [usersData] = useAtom(usersAtom) return (
{item.name} {item.targetCompletions && ( ({item.targetCompletions === 1 ? t('usesLeftSingular') : t('usesLeftPlural', { count: item.targetCompletions })}) )}
{item.description && ( {item.description} )}
{renderUserAvatars(item, currentUser as User, usersData)}
{item.coinCost} {t('coinsSuffix')}
{!item.archived && ( )} {!item.archived && ( {t('archiveButton')} )} {item.archived && ( {t('unarchiveButton')} )} {t('editButton')} {t('deleteButton')}
) }