import { notFound } from "next/navigation";

import { RulesPage } from "@/components/rules/RulesPage";
import { fetchProject, fetchRules } from "@/lib/api/server";

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

// 规则页（UX §7）。Server Component 取项目 + 规则列表；RulesPage（Client）承载新增。
export default async function RulesRoutePage({ params }: PageProps) {
  const { id } = await params;
  try {
    const project = await fetchProject(id);
    const rules = await fetchRules(id);
    return <RulesPage project={project} initialRules={rules.rules ?? []} />;
  } catch {
    notFound();
  }
}
