import AppProviders from "@/components/AppProviders";
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";

const display = Geist({
  subsets: ["latin"],
  variable: "--font-display"
});

const mono = Geist_Mono({
  subsets: ["latin"],
  variable: "--font-mono"
});

const themeScript = `(function(){try{var t=localStorage.getItem("agnet-theme")||"system";var d=t==="dark"||(t==="system"&&matchMedia("(prefers-color-scheme:dark)").matches);if(d)document.documentElement.classList.add("dark")}catch(e){}})()`;

export const metadata: Metadata = {
  title: "AGNET Global | Uzbekistan Agritech Platform",
  description:
    "AGNET connects Uzbekistan's farmers to finance, verified buyers, digital identity, inputs, and institutional rural intelligence.",
  metadataBase: new URL(process.env.NEXT_PUBLIC_SITE_URL || "https://agnet.global"),
  openGraph: {
    title: "AGNET Global | Uzbekistan Agritech Platform",
    description:
      "The integrated AgriTech platform for farmer finance, trade, and digital inclusion in Uzbekistan.",
    type: "website",
    siteName: "AGNET Global",
    locale: "en_US",
  },
  twitter: {
    card: "summary_large_image",
    title: "AGNET Global | Uzbekistan Agritech Platform",
    description: "Connecting Uzbekistan's farmers to formal finance, verified trade, and digital identity.",
  },
  other: {
    "application/ld+json": JSON.stringify({
      "@context": "https://schema.org",
      "@type": "Organization",
      name: "AGNET Global",
      url: "https://agnet.global",
      description: "Integrated AgriTech platform for farmer finance, trade, and digital inclusion in Uzbekistan.",
      address: {
        "@type": "PostalAddress",
        streetAddress: "IT-park resident, Uzbekistan Ovozi street 21 office number 2",
        addressLocality: "Tashkent",
        addressRegion: "Mirzo Uluqbek District",
        addressCountry: "UZ",
      },
      sameAs: [],
    }),
  },
};

export default function RootLayout({
  children
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en" className={`${display.variable} ${mono.variable}`} suppressHydrationWarning>
      <head>
        <script dangerouslySetInnerHTML={{ __html: themeScript }} />
      </head>
      <body>
        <AppProviders>{children}</AppProviders>
      </body>
    </html>
  );
}
