import { getServerSession } from '../../api/auth/[...nextauth]/auth';
import { PrismaClient } from '@repo/db';
import { PilotKurs, KursItem } from './_components/item';
import { RocketIcon } from '@radix-ui/react-icons';

export default async () => {
  const prisma = new PrismaClient();
  const session = await getServerSession();
  if (!session) return null;
  const user = session.user;
  const events = await prisma.event.findMany();
  if (!user) return null;

  return (
    <div className="grid grid-cols-6 gap-4">
      <div className="col-span-full">
        <p className="text-2xl font-semibold text-left flex items-center gap-2">
          <RocketIcon className="w-5 h-5" /> Events & Kurse
        </p>
      </div>
      <PilotKurs user={user} />
      {events.map((event) => (
        <KursItem user={user} event={event} key={event.id} />
      ))}
    </div>
  );
};
