import { Chat } from '@/components/chat';
import { auth } from '@/auth';
import { dbGetChat } from '@/lib/db/functions';
import { redirect } from 'next/navigation';
import { revalidatePath } from 'next/cache';

interface PageProps {
  params: {
    id: string;
  };
}

export default async function Page({ params }: PageProps) {
  const { id: chatId } = params;
  const chat = await dbGetChat(chatId);

  if (!chat) {
    revalidatePath('/');
    redirect('/');
  }
  const session = await auth();
  return <Chat chat={chat} session={session} />;
}
