import type { Metadata } from 'next'
import { redirect } from 'next/navigation'
import { getSession } from '@/lib/session'
import { getAllLinkEntries } from '@/lib/links-db'
import LinksClient from '../LinksClient'

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

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

  const entries = await getAllLinkEntries()

  return <LinksClient initialEntries={entries} />
}
