import { requireAdmin } from '@/lib/auth-guard'
import { prisma } from '@/lib/prisma'
import { JobsTable } from '@/components/admin/jobs-table'

export default async function AdminJobsPage() {
  await requireAdmin()

  const jobs = await prisma.claudeJob.findMany({
    orderBy: { created_at: 'desc' },
    take: 100,
    select: {
      id: true,
      kind: true,
      status: true,
      created_at: true,
      branch: true,
      pr_url: true,
      error: true,
      user: { select: { username: true } },
      product: { select: { name: true } },
    },
  })

  return (
    <div>
      <h1 className="text-xl font-semibold mb-4">Claude Jobs</h1>
      <JobsTable jobs={jobs} />
    </div>
  )
}
