import type { Metadata, Viewport } from "next";
import { Geist, Geist_Mono, Caveat } from "next/font/google";
import Script from "next/script";
import { SITE_URL, SITE_NAME } from "@/lib/seo";
import "./globals.css";

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

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

const caveat = Caveat({
  variable: "--font-caveat",
  subsets: ["latin"],
});

export const metadata: Metadata = {
  // Resolves all relative metadata URLs (OG/Twitter images, canonicals) to
  // absolute URLs — required for social previews to work.
  metadataBase: new URL(SITE_URL),
  title: {
    default: "Tia — Baby Tracker & Digital Heirloom",
    template: `%s | ${SITE_NAME}`,
  },
  description:
    "Track feeds, sleep, milestones, and memories. Tia is a privacy-first baby tracker and digital heirloom built for Indian families.",
  applicationName: SITE_NAME,
  authors: [{ name: "Tia" }],
  creator: "Tia",
  publisher: "Tia",
  category: "parenting",
  formatDetection: { telephone: false, email: false, address: false },
  // apple-touch-icon is provided by the src/app/apple-icon.png file convention.
  icons: {
    icon: "/icon.svg",
  },
  appleWebApp: {
    capable: true,
    statusBarStyle: "default",
    title: "Tia",
  },
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      "max-image-preview": "large",
      "max-snippet": -1,
      "max-video-preview": -1,
    },
  },
};

export const viewport: Viewport = {
  themeColor: "#fb7185",
};

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en-IN" suppressHydrationWarning>
      <body className={`${geistSans.variable} ${geistMono.variable} ${caveat.variable} min-h-full antialiased`}>
        {children}
        {/* Umami analytics — script served locally to avoid Cloudflare cross-origin 503.
            data-host-url tells the script where to POST events (analytics.manohargupta.com). */}
        <Script
          src="/umami.js"
          data-website-id="79444c19-ee31-4fab-baf5-f4e61098eeba"
          data-host-url="https://analytics.manohargupta.com"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}
