import { Geist, Geist_Mono } from "next/font/google";
import { NextAuthSessionProvider } from "./_components/AuthSessionProvider";
import { getServerSession } from "./api/auth/[...nextauth]/auth";
import "./globals.css";
import { CustomErrorBoundary } from "_components/ErrorBoundary";
import { Toaster } from "react-hot-toast";

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

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

const RootLayout = async ({
	children,
}: Readonly<{
	children: React.ReactNode;
}>) => {
	const session = await getServerSession();

	return (
		<html lang="en">
			<NextAuthSessionProvider session={session}>
				<body className={`${geistSans.variable} ${geistMono.variable} antialiased`}>
					<div>
						<Toaster
							containerStyle={{ zIndex: "999999999" }}
							position="top-center"
							reverseOrder={false}
						/>
					</div>
					<CustomErrorBoundary>{children}</CustomErrorBoundary>
				</body>
			</NextAuthSessionProvider>
		</html>
	);
};

RootLayout.displayName = "RootLayout";

export default RootLayout;
