import { NewsItem } from '@/types/news'; import { Card, CardContent, CardHeader } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Clock, Pin, ExternalLink, Eye, Trash2 } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useAuth } from '@/hooks/useAuth'; interface NewsCardProps { news: NewsItem; onTogglePin: (id: string) => void; onMarkAsRead: (id: string) => void; onDelete: (id: string) => void; onOpenArticle: (article: NewsItem) => void; } const NewsCard = ({ news, onTogglePin, onMarkAsRead, onDelete, onOpenArticle }: NewsCardProps) => { const { user } = useAuth(); // Function to decode HTML entities const decodeHtmlEntities = (text: string) => { const textarea = document.createElement('textarea'); textarea.innerHTML = text; return textarea.value; }; const getSourceColor = (category: string) => { switch (category) { case 'rss': return 'bg-blue-500/10 text-blue-700 border-blue-200'; case 'youtube': return 'bg-red-500/10 text-red-700 border-red-200'; case 'steam': return 'bg-gray-500/10 text-gray-700 border-gray-200'; case 'actualites': return 'bg-green-500/10 text-green-700 border-green-200'; default: return 'bg-muted text-muted-foreground'; } }; const getYouTubeVideoId = (url: string) => { const regex = /(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([^&\n?#]+)/; const match = url.match(regex); return match ? match[1] : null; }; const getYouTubeThumbnail = (url: string) => { const videoId = getYouTubeVideoId(url); return videoId ? `https://img.youtube.com/vi/${videoId}/hqdefault.jpg` : null; }; const handleCardClick = () => { onOpenArticle(news); // Don't automatically mark as read on card click - user can use the "Mark as read" button }; return (
{news.source}

{decodeHtmlEntities(news.title)}

{/* Show image only for non-YouTube articles */} {news.imageUrl && news.category !== 'youtube' && (
{news.title}
)} {news.category !== 'youtube' && (

{decodeHtmlEntities(news.description)}

)}
{new Date(news.publishedAt).toLocaleDateString('fr-FR', { day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit' })}
{!news.isRead && user && ( )} {news.url && ( )}
); }; export default NewsCard;