import { auth } from '@/auth'
import { redirect } from 'next/navigation'
import { prisma } from '@/lib/prisma'
import { getAgents } from '@/app/actions/agent-actions'
import { AgentsPageClient } from './agents-page-client'

export default async function AgentsPage() {
  const session = await auth()
  if (!session?.user?.id) redirect('/login')

  const userId = session.user.id

  const [agents, notebooks] = await Promise.all([
    getAgents(),
    prisma.notebook.findMany({
      where: { userId, trashedAt: null },
      orderBy: { order: 'asc' },
      select: { id: true, name: true, icon: true, parentId: true, trashedAt: true }
    })
  ])

  return (
    <AgentsPageClient
      agents={agents}
      notebooks={notebooks}
    />
  )
}
