import { getKolChanges, getKolDigest, getKolDivergence, getKolPosts } from '@/lib/api'
import type { Metadata } from 'next'
import KolPageClient from './KolPageClient'
import Breadcrumbs from '@/components/seo/Breadcrumbs'

const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || 'https://trumpsignal.com'
export const revalidate = 30

interface KolPageProps {
  params: Promise<{ locale: string }>
}

export async function generateMetadata({
  params,
}: KolPageProps): Promise<Metadata> {
  const { locale } = await params
  const isZh = false  // i18n shelved — Chinese branches kept as dead code for future revival; see messages/zh.json

  return {
    title: isZh ? 'KOL 信号与言行偏离追踪' : 'KOL Signals & Talks-vs-Trades Divergence',
    description: isZh
      ? '从 15 个加密 KOL 信息源中提取可执行观点，覆盖 Arthur Hayes、Delphi Digital、Bankless、Empire、Unchained 等，并追踪“说法”和链上仓位是否一致。'
      : 'AI-extracted crypto signals from 19 KOL feeds: Arthur Hayes, Delphi Digital, Bankless, Empire, Unchained and more. Includes talks-vs-trades divergence — when KOL wallets contradict their public posts.',
    keywords: isZh
      ? [
          'KOL 加密信号',
          'Arthur Hayes 信号',
          'Delphi Digital 分析',
          'KOL 钱包追踪',
          '言行不一致',
          '链上 KOL 跟踪',
          'Substack 加密信号',
          '播客加密信号',
        ]
      : [
          'KOL crypto signals',
          'Arthur Hayes signals',
          'Delphi Digital analysis',
          'crypto KOL tracker',
          'talks vs trades',
          'smart money divergence',
          'on-chain KOL tracking',
          'Substack crypto signals',
          'crypto podcast signals',
          'KOL wallet tracking',
        ],
    openGraph: {
      title: isZh ? 'KOL 信号与言行偏离 | Trump Alpha' : 'KOL Signals & Talks-vs-Trades | Trump Alpha',
      description: isZh
        ? '每天分析 KOL 长文、播客和公开观点，再与链上仓位交叉验证，找出真正有信息增量的观点与偏离。'
        : '19 KOL feeds (Hayes, Bankless, Empire…) AI-scored daily. Plus talks-vs-trades: when their wallets contradict their words.',
    },
    alternates: {
      canonical: `${siteUrl}/en/kol`,
      languages: {
        en: `${siteUrl}/en/kol`,
        'x-default': `${siteUrl}/en/kol`,
      },
    },
  }
}

// GEO: the KOL talks-vs-trades feed is a dataset cross-referencing 19 crypto
// KOLs' public statements against their on-chain wallet behaviour.
const kolDataset = {
  '@context': 'https://schema.org',
  '@type': 'Dataset',
  '@id': `${siteUrl}/en/kol#dataset`,
  name: 'Crypto KOL talks-vs-trades divergence dataset',
  description:
    'Daily cross-reference of 19 crypto KOLs\' public statements (Substack / podcast) against their on-chain Ethereum wallet activity, flagging divergence when public stance and real positioning disagree within a ±7-day window.',
  url: `${siteUrl}/en/kol`,
  keywords: ['crypto KOL', 'on-chain', 'divergence', 'wallet tracking', 'sentiment'],
  isAccessibleForFree: true,
  creator: { '@type': 'Organization', name: 'Endorphin', url: siteUrl },
  publisher: { '@id': `${siteUrl}/#org` },
  license: `${siteUrl}/en/terms`,
  measurementTechnique: 'On-chain wallet diff vs NLP stance extraction',
  temporalCoverage: '2025-01-01/..',
}

export default async function KolPage() {
  const [posts, digest, changes, divergence] = await Promise.all([
    getKolPosts({ limit: 100 }).catch(() => null),
    getKolDigest(7).catch(() => null),
    getKolChanges({ days: 7 }).catch(() => null),
    getKolDivergence({ days: 30 }).catch(() => null),
  ])

  return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(kolDataset) }}
      />
      <Breadcrumbs items={[{ name: 'KOL talks-vs-trades', path: '/en/kol' }]} />
      <KolPageClient
        initialPosts={posts?.items ?? null}
        initialDigest={digest}
        initialChanges={changes?.changes ?? null}
        initialDivergence={divergence?.items ?? null}
      />
    </>
  )
}
