import type { Metadata } from 'next'

import { PermissionGate } from '@/components/console/permission-gate'
import { ProofList } from '@/components/intelligence/proof-list'
import { DemoDataBadge, PageHeader } from '@/components/ui/display'
import { getCurrentUser } from '@/lib/auth/current-user'
import { DEMO_ASSET_CODE } from '@/lib/demo/config'
import { getI18n } from '@/lib/i18n/server'
import { listProofs } from '@/lib/services/proof-service'

export const metadata: Metadata = { title: 'Decision Proofs' }
export const dynamic = 'force-dynamic'

export default async function ProofsPage() {
  const user = await getCurrentUser()
  const { t } = await getI18n()
  if (!user?.permissions.has('proof.read')) return <PermissionGate />

  const proofs = await listProofs({ limit: 20 })

  return (
    <>
      <PageHeader
        title={t('proof.title')}
        subtitle={t('proof.subtitle')}
        badge={<DemoDataBadge label={t('common.simulated')} title={t('proof.note')} />}
      />
      <ProofList
        initialProofs={proofs}
        defaultAsset={DEMO_ASSET_CODE}
        canCreate={user.permissions.has('proof.create')}
      />
    </>
  )
}
