import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { gameHostingList, gameHostings, type GameHostSlug } from "@/lib/data/game-hosting";
import GameHostClient from "../GameHostClient";

type PageProps = {
  params: Promise<{ game: string }>;
};

export function generateStaticParams() {
  return gameHostingList.map((game) => ({ game: game.slug }));
}

export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
  const { game: slug } = await params;
  const game = gameHostings[slug as GameHostSlug];

  if (!game) {
    return {
      title: "Game Hosting",
    };
  }

  return {
    title: game.metaTitle,
    description: game.metaDescription,
    alternates: {
      canonical: game.href,
    },
    openGraph: {
      title: `${game.metaTitle} | Sonata Indonesia`,
      description: game.metaDescription,
      url: game.href,
      images: [{ url: game.heroImage, alt: game.heroAlt }],
    },
  };
}

export default async function GamePage({ params }: PageProps) {
  const { game: slug } = await params;
  const game = gameHostings[slug as GameHostSlug];

  if (!game) notFound();

  return <GameHostClient game={game} />;
}
