import { notFound } from "next/navigation";
import type { Metadata } from "next";
import MarketingRuntime from "@/components/MarketingRuntime";
import { BLOG_HTML, BLOG_SLUGS } from "@/content/blogIndex";
import { BLOG_META } from "@/content/blogMeta";

export const revalidate = 600;

export function generateStaticParams() {
  return BLOG_SLUGS.map((slug) => ({ slug }));
}

export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
  const { slug } = await params;
  const meta = BLOG_META[slug];
  if (!meta) return { title: "Health Journal — Awafi Drugstore" };
  return {
    title: `${meta.title} — Awafi Drugstore`,
    description: meta.description,
    openGraph: { title: meta.title, description: meta.description, type: "article" },
  };
}

export default async function BlogPostPage({ params }: { params: Promise<{ slug: string }> }) {
  const { slug } = await params;
  const html = BLOG_HTML[slug];
  if (!html) notFound();
  return (
    <>
      <link rel="stylesheet" href="/css/pages/blog.css" />
      <MarketingRuntime html={html} />
    </>
  );
}
