'use client'; import { useEffect, useState } from 'react'; import ReactMarkdown from 'react-markdown'; import { Link } from '@/lib/navigation'; import { getLocalizedValue } from '@/lib/i18n'; interface NewsItem { id: number; title: any; content: any; author: string | null; publishedAt: string; featured: boolean; special: { id: number; name: any; } | null; } interface NewsSectionProps { locale: string; } export default function NewsSection({ locale }: NewsSectionProps) { const [news, setNews] = useState([]); const [isExpanded, setIsExpanded] = useState(false); const [loading, setLoading] = useState(true); useEffect(() => { fetchNews(); }, [locale]); const fetchNews = async () => { try { const res = await fetch(`/api/news?limit=3&locale=${locale}`); if (res.ok) { const data = await res.json(); setNews(data); } } catch (error) { console.error('Failed to fetch news:', error); } finally { setLoading(false); } }; if (loading || news.length === 0) { return null; // Don't show anything if no news } return (
{/* Header */} {/* Content */} {isExpanded && (
{news.map((item, index) => (
{/* Title */}
{item.featured && ( ⭐ FEATURED )}

{getLocalizedValue(item.title, locale)}

{/* Metadata */}
{new Date(item.publishedAt).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric' })} {item.author && ( <> by {item.author} )} {item.special && ( <> ★ {getLocalizedValue(item.special.name, locale)} )}
{/* Content */}

{children}

, a: ({ children, href }) => ( {children} ), strong: ({ children }) => {children}, em: ({ children }) => {children}, ul: ({ children }) =>
    {children}
, ol: ({ children }) =>
    {children}
, li: ({ children }) =>
  • {children}
  • }} > {getLocalizedValue(item.content, locale)}
    ))}
    )}
    ); }