// app/page.tsx
import { renderPostContent } from '@/components/WPRenderer/WPRenderer';
import { PostData } from '@/types/entities';

export const revalidate = 10;

export default async function HomePage() {
    const baseUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000';

    const res = await fetch(`${baseUrl}/api/home`, { next: { revalidate: 10 }, });

    if (!res.ok) {
        // 🚨 REQUIRED for stale reuse
        throw new Error('Failed to fetch home posts');
    }

    const posts: PostData[] = await res.json();

    return (
        <div className="w-full flex flex-col items-center">
            {posts.map(post => (
                <div key={post.ID} className="max-w-5xl">
                    {renderPostContent(post.post_content)}
                </div>
            ))}
        </div>
    );
}
