import type { Metadata, Viewport } from "next";
import "./globals.css";
import { SITE_URL, SOCIAL_IMAGE } from "@/lib/site-config";
import { isLanguage, languages } from "@/lib/i18n";

const siteUrl = SITE_URL;

export const metadata: Metadata = {
  metadataBase: new URL(siteUrl),
  applicationName: "AMM Correlated-Pairs Liquidity",
  title: "AMM Correlated-Pairs Liquidity",
  description: "Explore live AMM liquidity, trading routes, venues, and correlated token pairs on Robinhood, Ethereum L1, and Base.",
  keywords: ["Robinhood Chain", "AMM", "DEX", "liquidity", "correlated pairs", "Uniswap", "DeFi", "tokenized equities"],
  category: "finance",
  alternates: {
    canonical: "/",
    languages: { en: "/", "zh-CN": "/zh", es: "/es", ja: "/ja", ko: "/ko", fr: "/fr", "pt-BR": "/pt", de: "/de" },
  },
  openGraph: {
    type: "website",
    images: [SOCIAL_IMAGE],
    url: "/",
    siteName: "AMM Correlated-Pairs Liquidity",
    title: "AMM Correlated-Pairs Liquidity",
    description: "A live, open-source map of AMM liquidity and correlated trading routes on Robinhood, Ethereum L1, and Base.",
  },
  twitter: {
    card: "summary_large_image",
    images: [SOCIAL_IMAGE.url],
    title: "AMM Correlated-Pairs Liquidity",
    description: "A live, open-source map of AMM liquidity and correlated trading routes on Robinhood, Ethereum L1, and Base.",
  },
  robots: { index: true, follow: true, googleBot: { index: true, follow: true, "max-image-preview": "large", "max-snippet": -1 } },
  manifest: "/site.webmanifest",
  icons: {
    icon: "/favicon.svg",
    shortcut: "/favicon.svg",
  },
  other: { "agent-discovery": "/AGENTS.txt", "llms-txt": "/llms.txt" },
};

export const viewport: Viewport = { width: "device-width", initialScale: 1, colorScheme: "light", themeColor: "#f4f5f6" };

export default async function RootLayout({
  children, params,
}: Readonly<{
  children: React.ReactNode;
  params: Promise<{ lang?: string }>;
}>) {
  const { lang } = await params;
  const htmlLang = lang && isLanguage(lang) ? languages.find(l => l.code === lang)!.htmlLang : "en";
  return (
    <html lang={htmlLang}>
      <body className="antialiased">{children}</body>
    </html>
  );
}
