import type { Metadata, Viewport } from "next";
import { Plus_Jakarta_Sans, Playfair_Display, Geist_Mono } from "next/font/google";
import { ClerkProvider } from "@clerk/nextjs";
import { ThemeProvider } from "@/components/theme-provider";
import { PostHogProvider } from "@/lib/analytics/posthog-provider";
import "./globals.css";

const sans = Plus_Jakarta_Sans({
  variable: "--font-sans",
  subsets: ["latin"],
  weight: ["400", "500", "600", "700", "800"],
  display: "swap",
});

const serif = Playfair_Display({
  variable: "--font-serif",
  subsets: ["latin"],
  weight: ["400", "600", "700"],
  display: "swap",
});

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

const APP_URL = process.env.NEXT_PUBLIC_APP_URL || "https://nigerialisting.vercel.app";

export const viewport: Viewport = {
  width: "device-width",
  initialScale: 1,
  maximumScale: 1,
  userScalable: false,
  viewportFit: "cover",
};

export const metadata: Metadata = {
  metadataBase: new URL(APP_URL),
  title: {
    default: "Nigeria Listing | Verified Real Estate Marketplace",
    template: "%s | Nigeria Listing",
  },
  description:
    "Nigeria's trusted real estate marketplace for verified properties. Buy, sell, or rent houses, luxury duplexes, lands, shortlets, and commercial spaces with authenticated titles across Lagos, Abuja, and all Nigerian states.",
  keywords: [
    "Nigeria real estate",
    "verified properties Nigeria",
    "houses for sale in Lagos",
    "duplex in Lekki",
    "property in Abuja",
    "land for sale Nigeria",
    "Certificate of Occupancy",
    "Governor Consent",
    "luxury shortlet Lagos",
    "real estate agents Nigeria",
  ],
  authors: [{ name: "Nigeria Listing", url: APP_URL }],
  creator: "Nigeria Listing",
  publisher: "Nigeria Listing Ltd",
  alternates: {
    canonical: "/",
  },
  icons: {
    icon: "/asset/logo.png",
    apple: "/asset/logo.png",
  },
  openGraph: {
    type: "website",
    locale: "en_NG",
    url: APP_URL,
    title: "Nigeria Listing | Verified Real Estate Marketplace",
    description:
      "Find authenticated houses, luxury duplexes, lands, shortlets, and commercial properties across Nigeria with verified land titles.",
    siteName: "Nigeria Listing",
    images: [
      {
        url: "/asset/logo.png",
        width: 800,
        height: 800,
        alt: "Nigeria Listing - Verified Real Estate Marketplace",
      },
    ],
  },
  twitter: {
    card: "summary_large_image",
    title: "Nigeria Listing | Verified Real Estate Marketplace",
    description:
      "Find authenticated houses, luxury duplexes, lands, shortlets, and commercial properties across Nigeria with verified land titles.",
    images: ["/asset/logo.png"],
  },
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      "max-video-preview": -1,
      "max-image-preview": "large",
      "max-snippet": -1,
    },
  },
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <ClerkProvider>
      <html
        lang="en"
        suppressHydrationWarning
        className={`${sans.variable} ${serif.variable} ${mono.variable} antialiased`}
      >
        <body className="min-h-screen flex flex-col font-sans bg-background text-foreground selection:bg-primary/20 selection:text-primary">
          <ThemeProvider defaultTheme="light" storageKey="jaz-theme">
            <PostHogProvider>
              {children}
            </PostHogProvider>
          </ThemeProvider>
        </body>
      </html>
    </ClerkProvider>
  );
}
