"use server";

import BlogArticle from "@/components/article";
import getMe from "@/lib/getMe";
import request from "@/lib/request";
import { Blog } from "@/types/types";
import { notFound } from "next/navigation";

export default async function HistoryDetails({
	params,
}: {
	params: Promise<{ slug: string }>;
}) {
	const { slug } = await params;
	const blog = await request<Blog>(`/blogs/${slug}`, {
		csrfToken: false,
		requiresAuth: false,
	});

	if (blog.status === "Error" || !blog.data) {
		return notFound();
	}

	const me = await getMe();

	return <BlogArticle blog={blog.data} user={me?.data} />;
}
