"use client";

import "./globals.css";
import "leaflet/dist/leaflet.css";
import { Geist, Geist_Mono, Inter, Onest } from "next/font/google";

import { Providers } from "@/shared/providers";
import { Toaster } from "@/shared/components/ui/sonner";
import { appConfig } from "@/shared/config/app-config";
import Script from "next/script";

const interSans = Inter({
  variable: "--font-inter-sans",
  subsets: ["latin"],
  display: "swap",
  style: "normal",
  weight: ["400", "500", "600", "700"],
  fallback: ["system-ui", "sans-serif"],
  preload: true,
});

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

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

const onest = Onest({
  variable: "--font-onest-sans",
  subsets: ["latin"],
  display: "swap",
  style: "normal",
  weight: ["400", "500", "600", "700"],
  fallback: ["system-ui", "sans-serif"],
  preload: true,
});

export default function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  return (
    <html lang="en">
      <body
        className={`${geistMono.variable} ${geistSans.variable} ${interSans.variable} ${onest.variable} font-sans antialiased`}
      >
        <head>
          <title>{`Satu Peta ${appConfig.wilayah}`}</title>
        </head>

        <Script
          src="https://www.googletagmanager.com/gtag/js?id=G-W8433HFYHH"
          strategy="afterInteractive"
        />
        <Script id="google-analytics" strategy="afterInteractive">
          {`
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', 'G-W8433HFYHH');
          `}
        </Script>

        <Providers>
          {children}
          <Toaster style={{ zIndex: 9999 }} />
        </Providers>
      </body>
    </html>
  );
}
