import ChatClient from './ChatClient';
import { auth } from '@/auth';
import { dbGetChat } from '@/lib/db/functions';
import { redirect } from 'next/navigation';
import { revalidatePath } from 'next/cache';

interface ChatServerProps {
  id: string;
}

export default async function ChatServer({ id }: ChatServerProps) {
  const chat = await dbGetChat(id);

  if (!chat) {
    revalidatePath('/');
    redirect('/');
  }
  return <ChatClient chat={chat} />;
}
