/* eslint-disable react/jsx-props-no-spreading */
import { FC, PropsWithChildren } from "react";
import { SessionProvider } from "next-auth/react";
import { CssBaseline } from "@mui/material";
import { CookiesProvider } from "react-cookie";
import { I18n } from "react-polyglot";
import { AdapterDateFns } from "@mui/x-date-pickers-pro/AdapterDateFns";
("use client");

import { LocalizationProvider } from "@mui/x-date-pickers-pro";
import { AppProvider } from "@/app/_components/AppProvider";
import { NextAppDirEmotionCacheProvider } from "tss-react/next/appDir";
import en from "locales/en.json";
import fr from "locales/fr.json";
import "@fontsource/poppins/400.css";
import "@fontsource/poppins/700.css";
import "@fontsource/roboto/400.css";
import "@fontsource/roboto/700.css";
import "@fontsource/playfair-display/900.css";
import "styles/global.css";
import { LicenseInfo } from "@mui/x-data-grid-pro";

LicenseInfo.setLicenseKey(process.env.MUI_LICENSE_KEY ?? "");

const messages: any = { en, fr };

export const MultiProvider: FC<PropsWithChildren> = ({ children }: any) => {
  // const { locale = "en" } = useRouter();
  const locale = "en";

  return (
    <NextAppDirEmotionCacheProvider options={{ key: "css" }}>
      <SessionProvider>
        <CookiesProvider>
          <CssBaseline />
          <AppProvider>
            <LocalizationProvider dateAdapter={AdapterDateFns}>
              <I18n locale={locale} messages={messages[locale]}>
                {children}
              </I18n>
            </LocalizationProvider>
          </AppProvider>
        </CookiesProvider>
      </SessionProvider>
    </NextAppDirEmotionCacheProvider>
  );
};
