import { notFound } from "next/navigation";
import { getAllGames, getGame } from "@/lib/content";
import BookCover from "@/components/BookCover";

interface PageProps {
  params: { game: string };
}

export async function generateStaticParams() {
  const games = getAllGames();
  return games.map((game) => ({ game: game.slug }));
}

export async function generateMetadata({ params }: PageProps) {
  try {
    const game = getGame(params.game);
    return {
      title: `${game.title} | Cronicas de los Reinos`,
      description: game.description,
    };
  } catch {
    return { title: "No encontrado" };
  }
}

export default function GamePage({ params }: PageProps) {
  try {
    const game = getGame(params.game);
    return <BookCover game={game} />;
  } catch {
    notFound();
  }
}
