import { prisma } from "@/prisma/prismaClient";
import Link from "next/link";

export default async function GameSystem({
  params: { id },
}: {
  params: { id: string };
}) {
  if (!id) throw "HOW DID YOU GET HERE?";

  const gameSystem = await prisma.gameSystem.findFirst({
    where: {
      id,
    },
    include: {
      schemas: {
        select: {
          name: true,
          id: true,
          publications: {
            select: {
              name: true,
              id: true,
            },
          },
        },
      },
    },
    // select: {
    //   id: true,
    //   name: true,
    // },
  });

  return (
    <>
      <section className="heading">
        <h2 className="strapline">Game System</h2>
        <h1>{gameSystem?.name}</h1>
      </section>
      <section>
        <>
          <div>
            <Link
              className="btn-primary mb-6 block w-min whitespace-nowrap"
              href={`/game-systems/${id}/schema/create`}
            >
              Create New Schema
            </Link>
          </div>
          <ul>
            {gameSystem?.schemas.map((schema) => (
              <li key={schema.id}>{schema.name}</li>
            ))}
            {!gameSystem?.schemas.length && (
              <li>No schemas for {gameSystem?.name}</li>
            )}
          </ul>
        </>
      </section>
    </>
  );
}
