import { notFound } from "next/navigation";
import { BlogEditor } from "@/components/BlogEditor";
import { getPostById } from "@/lib/blog";

export default async function EditBlogPostPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const post = await getPostById(id);
  if (!post) notFound();
  return (
    <div className="mx-auto max-w-3xl px-4 py-10">
      <a href="/admin/blog" className="text-sm text-terra">
        ← All posts
      </a>
      <h1 className="font-display mt-3 text-4xl text-forest">Edit post</h1>
      <div className="mt-8 rounded-3xl border border-forest/10 bg-cream p-6">
        <BlogEditor
          postId={post.id}
          initial={{
            title: post.title,
            slug: post.slug,
            excerpt: post.excerpt,
            body: post.body,
            cover_url: post.cover_url || "",
            status: post.status,
          }}
        />
      </div>
    </div>
  );
}
