import { prisma } from '@repo/db';
import { Form } from '../_components/Form';

export default async ({ params }: { params: Promise<{ id: string }> }) => {
  const { id } = await params;
  const event = await prisma.event.findUnique({
    where: {
      id: parseInt(id),
    },
  });
  const users = await prisma.user.findMany({
    select: {
      id: true,
      firstname: true,
      lastname: true,
      publicId: true,
    },
  });
  const appointments = await prisma.eventAppointment.findMany({
    where: {
      eventId: parseInt(id),
    },
  });
  if (!event) return <div>Event not found</div>;
  return <Form event={event} users={users} appointments={appointments} />;
};
