import { getPostGrid } from "@/lib/get-post-grid";
import { PostData } from "@/types/entities";

export default async function PostGrid({ id, page }: { id: number; page?: number }) {
    const data = await getPostGrid(id, page || 1);
    if (!data) return null;

    return (
        <section className="post-grid">
            <div className="grid">
                {data.posts.map((post: PostData) => (
                    <article key={post.ID}>
                        <h3>
                            <a href={`/${post.post_name}`}>{post.post_title}</a>
                        </h3>
                        {post.post_excerpt && <p>{post.post_excerpt}</p>}
                    </article>
                ))}
            </div>
            {/* optional WP-style pagination component */}
        </section>
    );
}
