import type { Metadata } from 'next'
import { redirect } from 'next/navigation'
import { getSession } from '@/lib/session'
import { listUsers } from '@/lib/users'
import UsersClient from './UsersClient'

export const metadata: Metadata = {
  title: 'Admin — Backerup',
}

export default async function AdminPage() {
  const session = await getSession()
  if (!session || session.role !== 'admin') {
    redirect('/')
  }

  const users = await listUsers()

  return <UsersClient initialUsers={users} currentUserId={session.userId} />
}
