---
import { getCollection, getEntryBySlug } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro';

export async function getStaticPaths() {
  const posts = await getCollection('blog');
  return posts.map(post => ({
    params: { slug: post.slug },
    props: { post },
  }));
}

const { post } = Astro.props;
const { Content } = await post.render();

// Handle undefined or null values
const title = post.data.title || '';
const description = post.data.description || '';
const pubDate = post.data.pubDate ? new Date(post.data.pubDate) : new Date();
const updatedDate = post.data.updatedDate ? new Date(post.data.updatedDate) : undefined;
const heroImage = post.data.heroImage || undefined;
const category = post.data.category || undefined;
const tags = post.data.tags || [];
const draft = post.data.draft || false;
---

<BlogPost
  title={title}
  description={description}
  pubDate={pubDate}
  updatedDate={updatedDate}
  heroImage={heroImage}
  category={category}
  tags={tags}
  draft={draft}
>
  <Content />
</BlogPost> 