import type { Metadata } from "next";
import { headers } from "next/headers";
import "./globals.css";

export async function generateMetadata(): Promise<Metadata> {
  const requestHeaders = await headers();
  const host = requestHeaders.get("x-forwarded-host") ?? requestHeaders.get("host") ?? "localhost:3000";
  const protocol = requestHeaders.get("x-forwarded-proto") ?? (host.startsWith("localhost") ? "http" : "https");
  const metadataBase = new URL(`${protocol}://${host}`);

  return {
    metadataBase,
    title: "高徳乐 AI 舵机选型助手",
    description: "高徳乐280个产品型号完整目录，支持搜索筛选、AI舵机初选与样品申请。",
    openGraph: {
      title: "高徳乐 AI 舵机选型助手",
      description: "280个型号完整目录。3分钟找到适合你的舵机，AI初选，工程师复核。",
      images: [{ url: new URL("/og.png", metadataBase).toString(), width: 1200, height: 630 }],
      type: "website",
    },
    twitter: {
      card: "summary_large_image",
      title: "高徳乐 AI 舵机选型助手",
      description: "3分钟，找到适合你的舵机。",
      images: [new URL("/og.png", metadataBase).toString()],
    },
  };
}

export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
  return (
    <html lang="zh-CN">
      <body>{children}</body>
    </html>
  );
}
