import { getUsersPage } from "@/lib/db/admin-queries"
import { UsersTable } from "@/components/admin/users-table"

export const dynamic = "force-dynamic"

export default async function AdminUsersPage({
  searchParams,
}: {
  searchParams: Promise<{ q?: string; page?: string; plan?: string; sort?: string; dir?: string }>
}) {
  const { q, page, plan, sort, dir } = await searchParams

  const result = await getUsersPage({
    q,
    page: Number(page) || 1,
    plan,
    sort,
    dir: dir === "asc" ? "asc" : dir === "desc" ? "desc" : undefined,
  })

  return (
    <div className="space-y-6">
      <div>
        <h1 className="text-xl font-bold text-white">Users</h1>
        <p className="mt-1 text-sm text-white/40">
          Manage accounts, plans and access across the platform.
        </p>
      </div>

      <UsersTable data={result} query={{ q, plan, sort, dir }} />
    </div>
  )
}
