import { Geist, Geist_Mono, Inter } from "next/font/google";
import "./globals.css";
import { description as defaultDescription } from "@/config/default";
import StoreProvider from "@/utils/store/store.provider";
import Notification from "@/components/ui/Notification/notification";
import Modal from "@/components/administrator/Modal/modal";
import Toast from "@/components/ui/Toast/toast";
import MiniWindow from "@/components/administrator/MiniWondow/mini.window";
import { getOrigin } from "@/models/helper";
import VisitorProvider from "@/providers/visitor.provider";
import { decodeAccessToken, decodeAnonymous } from "@/utils/cookie";
// import { GoogleAnalytics, GoogleTagManager } from "@next/third-parties/google";
// import Script from "next/script";
import G_TagManager from "@/components/google/google.tag.manager";
import G_Analytics from "@/components/google/google.analytics";
import { getGeneralSettings } from "@/models/settings";

// const geistSans = Geist({
//   variable: "--font-geist-sans",
//   subsets: ["latin"],
//   weight: ["100", "200", "300", "400", "500", "600", "700", "800", "900"],
// });

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

const inter = Inter({
  variable: "--font-inter",
  subsets: ["latin"],
  weight: ["100", "200", "300", "400", "500", "600", "700", "800", "900"],
});

export async function generateMetadata() {
  const origin = await getOrigin();
  let description = await getGeneralSettings();

  if (!description) description = defaultDescription;

  return {
    metadataBase: new URL(origin),
    title: description.title,
    description: description.description,
    openGraph: {
      title: description.title,
      description: description.description,
      images: description.logo,
      type: "website",
    },
  };
}

export default async function RootLayout({ children }) {
  const accessToken = await decodeAccessToken();
  const anonymous = await decodeAnonymous();

  let description = await getGeneralSettings();

  if (!description) description = defaultDescription;

  return (
    <StoreProvider>
      <html lang="en">
        <body
          // className={`${geistSans.variable}`}
          className={inter.className}>
          <G_TagManager description={description} />
          <VisitorProvider
            description={description}
            userData={accessToken?.data}
            anonymous={anonymous?.data}>
            {children}
          </VisitorProvider>
          <MiniWindow />
          <Notification />
          <Modal />
          <Toast />
          <G_Analytics description={description} />
        </body>
      </html>
    </StoreProvider>
  );
}
