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

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

  const products = await prisma.product.findMany({
    orderBy: { created_at: 'desc' },
    select: {
      id: true,
      name: true,
      archived: true,
      created_at: true,
      user: { select: { username: true } },
      _count: { select: { members: true, pbis: true } },
    },
  })

  return (
    <div>
      <h1 className="text-xl font-semibold mb-4">Producten</h1>
      <ProductsTable products={products} />
    </div>
  )
}
