import type { Metadata } from 'next'

import { MapExplorer } from '@/components/console/map-explorer'
import { PermissionGate } from '@/components/console/permission-gate'
import { DemoDataBadge, PageHeader } from '@/components/ui/display'
import { getCurrentUser } from '@/lib/auth/current-user'
import { getI18n } from '@/lib/i18n/server'
import { getMapData } from '@/lib/services/map-service'

export const metadata: Metadata = { title: 'National map' }
export const dynamic = 'force-dynamic'

export default async function MapPage() {
  const user = await getCurrentUser()
  const { t } = await getI18n()

  if (!user?.permissions.has('grid.map.read')) return <PermissionGate />

  const { assets, regions } = await getMapData()

  return (
    <>
      <PageHeader
        title={t('map.title')}
        subtitle={t('map.subtitle')}
        badge={<DemoDataBadge label={t('common.simulated')} title={t('common.simulatedTooltip')} />}
      />
      <MapExplorer assets={assets} regions={regions} />
    </>
  )
}
