// app/[slug]/page.tsx
import Post from '@/components/Post/Post';
import { renderPostContent } from '@/components/WPRenderer/WPRenderer';

// ISR: regenerate every 60 seconds
export const revalidate = 60;

export interface PageProps {
    params: {
        slug: string;
    };
}

export default async function PostPage({ params }: PageProps) {
    const { slug } = await params;

    const baseUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000';

    const res = await fetch(`${baseUrl}/api/posts/${slug}`, {
        next: { revalidate: 60 },
    });

    if (!res.ok) {
        console.log(`${baseUrl}/api/posts/${slug}`)
        // 🚨 THROW — this is critical
        throw new Error('Failed to fetch post');
    }

    const post = await res.json();

    return (
        <Post post={post} />
    );
}
