import type { Metadata } from "next";
import { GameForm } from "@/components/admin/GameForm";
import { requireAdmin, createGameAction } from "@/lib/admin-actions";
import { db } from "@/lib/db";

export const metadata: Metadata = {
  title: "Add Game",
  description: "Add a game to the catalog.",
};

export default async function NewGamePage() {
  await requireAdmin();
  const categories = await db.category.findMany({
    orderBy: { name: "asc" },
    select: { id: true, name: true },
  });

  return (
    <div>
      <h1 className="text-2xl font-bold text-white sm:text-3xl">Add game</h1>
      <p className="mt-1 mb-6 text-sm text-slate-400">
        Verify the source and embed permission before publishing. New games
        start as drafts unless you choose otherwise.
      </p>
      <GameForm
        categories={categories}
        action={createGameAction}
        submitLabel="Add game"
      />
    </div>
  );
}
