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

export const viewport: Viewport = {
  width: "device-width",
  initialScale: 1,
  viewportFit: "cover",
  themeColor: "#18201f",
};

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.includes("localhost") ? "http" : "https");
  const base = new URL(`${protocol}://${host}`);
  return {
    metadataBase: base,
    title: "FlowMoments | Digital Photo & Message Walls for Events",
    description: "Create a live digital photo and message wall for weddings, community events, celebrations and company occasions. Collect, approve and display guest moments beautifully.",
    applicationName: "FlowMoments",
    keywords: ["digital photo wall", "event photo wall", "wedding message wall", "live event wall", "guest photo submission", "digital guestbook"],
    alternates: { canonical: "/" },
    robots: { index: true, follow: true },
    icons: { icon: "/favicon.svg" },
    openGraph: {
      title: "FlowMoments",
      description: "Collect guest photos and messages. Approve them. Watch your live event wall come alive.",
      type: "website",
      siteName: "FlowMoments",
      url: "/",
      images: [{ url: new URL("/og.png", base).toString(), width: 1731, height: 909, alt: "FlowMoments guest contribution and live event wall" }],
    },
    twitter: {
      card: "summary_large_image",
      title: "FlowMoments",
      description: "Digital photo and message walls for moments worth sharing.",
      images: [new URL("/og.png", base).toString()],
    },
  };
}

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