import { notFound } from "next/navigation";

import { OutlineEditor } from "@/components/outline/OutlineEditor";
import { fetchOutline, fetchProject } from "@/lib/api/server";

interface PageProps {
  params: Promise<{ id: string }>;
}

// 大纲编辑器页（UX §6.7）。Server Component 取项目 + 已存大纲（GET .../outline，
// 空/错误降级为空列表）作为初始章节，重访时显已生成的大纲；OutlineEditor（Client）
// 仍按需触发 POST .../outline 生成/覆盖所显章节。
export default async function OutlinePage({ params }: PageProps) {
  const { id } = await params;
  try {
    const project = await fetchProject(id);
    const initialChapters = await fetchOutline(id);
    return (
      <OutlineEditor project={project} initialChapters={initialChapters} />
    );
  } catch {
    notFound();
  }
}
