import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import { headers } from "next/headers";
import "./globals.css";

const geistSans = Geist({ variable: "--font-geist-sans", subsets: ["latin"] });
const geistMono = Geist_Mono({ variable: "--font-geist-mono", subsets: ["latin"] });

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

  return {
    metadataBase: new URL(origin),
    title: "ConnectPoint Learning — Learn. Build. Prove.",
    description: "Learn practical skills, build real work and turn verified evidence into career experience.",
    openGraph: {
      title: "ConnectPoint Learning — Learn. Build. Prove.",
      description: "Turn practical skills into real career experience.",
      images: [{ url: `${origin}/og.png`, width: 1200, height: 630, alt: "ConnectPoint Learning — Learn. Build. Prove." }],
    },
    twitter: {
      card: "summary_large_image",
      title: "ConnectPoint Learning — Learn. Build. Prove.",
      description: "Turn practical skills into real career experience.",
      images: [`${origin}/og.png`],
    },
  };
}

export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
  return <html lang="en"><body className={`${geistSans.variable} ${geistMono.variable}`}>{children}</body></html>;
}
