import { AuthLayout } from '@/src/components/auth/AuthLayout';
import RegisterForm from '@/src/components/auth/RegisterForm';
import { db } from '@/lib/db';
import { notFound } from 'next/navigation';

export default async function InvitationRegisterPage({ params }: { params: Promise< { token: string }> }) {
  const { token } = await params;
  const invitation = await db.invitation.findUnique({
    where: { token },
    include: { portfolio: true }
  });

  if (!invitation || invitation.acceptedAt) {
    notFound();
  }

  return (
    <AuthLayout
      title={`Create your account and collaborate on ${invitation.portfolio.title}`}
    >
      <RegisterForm 
        isInvitation={true}
        invitationData={{
          token: token,
          email: invitation.email,
          portfolioId: invitation.portfolioId,
          portfolioTitle: invitation.portfolio.title
        }}
      />
    </AuthLayout>
  );
}