import type { Metadata } from 'next'; import { Suspense } from 'react'; import { t } from '@/i18n'; import { isNotBuilt } from '@/lib/api'; import { apiAnalytics } from '@/lib/api-analytics'; import { routes } from '@/lib/site'; import type { PeersResponse } from '@/lib/types-analytics'; import { NotBuiltState } from '@/components/data/empty-state'; import { PageHeader } from '@/components/explore/page-header'; import { PeersView } from '@/components/peers/peers-view'; export const revalidate = 900; type SP = Record; function slug(v: string | string[] | undefined): string | undefined { const s = (Array.isArray(v) ? v[0] : v) ?? ''; return /^[a-z0-9][a-z0-9-]*$/.test(s) ? s : undefined; } export async function generateMetadata({ searchParams }: { searchParams: Promise }): Promise { const sp = await searchParams; const custom = !!(slug(sp.x) || slug(sp.y) || sp.year || sp.method); return { title: t('peers.metaTitle'), description: t('peers.description'), alternates: { canonical: routes.peers() }, robots: custom ? { index: false, follow: true } : undefined }; } export default async function PeersPage({ searchParams }: { searchParams: Promise }) { const sp = await searchParams; const year = Number(Array.isArray(sp.year) ? sp.year[0] : sp.year); const method = (Array.isArray(sp.method) ? sp.method[0] : sp.method) === 'ols' ? 'ols' : 'theil-sen'; let data: PeersResponse | null = null; try { data = await apiAnalytics.peers({ x: slug(sp.x), y: slug(sp.y), year: Number.isInteger(year) && year > 1800 ? year : null, method }); } catch (e) { if (isNotBuilt(e)) return ; data = null; } return ( <> {!data ? (

{t('peers.unavailable')}

) : ( )} ); }