---
import { type CollectionEntry, getCollection, render } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro';
import { calculateReadingTime } from '../../utils/reading-time';

export async function getStaticPaths() {
	const posts = await getCollection('blog');

	return posts.map((post) => ({
		params: { slug: post.id },
		props: { post },
	}));
}

interface Props {
	post: CollectionEntry<'blog'>;
}

const { post } = Astro.props;
const { Content } = await render(post);
const readTimeText = calculateReadingTime(post.body);
---

<BlogPost {...post.data} readTime={readTimeText}>
	<Content />
</BlogPost>
