import { LiquidityNetwork } from "./liquidity-network";
import { copy, languagePath, type Language } from "@/lib/i18n";
import { bundledSnapshots } from "@/lib/bundled-snapshots";
import { CHAINS, DEFAULT_CHAIN, type ChainId } from "@/lib/chains";
import type { SnapshotSet } from "@/lib/liquidity-set";
import { SITE_URL, REPOSITORY_PATH, REPOSITORY_NAME } from "@/lib/site-config";

const siteUrl = SITE_URL;

export function SitePage({ language, chain = DEFAULT_CHAIN.id }: { language: Language; chain?: ChainId }) {
  const t = copy[language];
  const initialSnapshots = Object.fromEntries(CHAINS.map(({ id }) => [id, { ...bundledSnapshots[id], stale: true }])) as SnapshotSet;
  const initialData = initialSnapshots[chain];
  const structuredData = {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "WebApplication",
        name: t.title,
        description: t.description,
        url: `${siteUrl}${languagePath(language)}`,
        applicationCategory: "FinanceApplication",
        operatingSystem: "Any",
        isAccessibleForFree: true,
        inLanguage: language,
        dateModified: initialData.updatedAt,
        featureList: ["Live AMM liquidity graph", "Correlated-pair routing", "Multi-venue aggregation", "Open-source clone"],
      },
      {
        "@type": "Dataset",
        name: "Robinhood, Ethereum L1, and Base AMM liquidity snapshots",
        description: "Aggregated AMM pools, assets, venues, volume, liquidity, and trading routes on Robinhood, Ethereum L1, and Base.",
        url: `${siteUrl}/data/latest.json`,
        dateModified: initialData.updatedAt,
        creator: { "@type": "Organization", name: "GeckoTerminal", url: "https://www.geckoterminal.com" },
        measurementTechnique: "Top four indexed pool pages, deduplicated by pool ID. Asset-class grouping is not measured price correlation.",
        isAccessibleForFree: true,
      },
      {
        "@type": "SoftwareSourceCode",
        name: "AMM Correlated-Pairs Liquidity",
        codeRepository: `${siteUrl}${REPOSITORY_PATH}`,
        downloadUrl: `${siteUrl}/${REPOSITORY_NAME}.tar.gz`,
        programmingLanguage: ["TypeScript", "React", "CSS"],
        license: "https://opensource.org/license/mit",
      },
    ],
  };

  return <>
    <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData).replace(/</g, "\\u003c") }} />
    <LiquidityNetwork initialSnapshots={initialSnapshots} initialChain={chain} initialLanguage={language} />
  </>;
}
