"use client";

/* 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";
import { LocalizationProvider } from "@mui/x-date-pickers-pro";
import { AppProvider } from "app/_components/AppProvider";
import { NextAppDirEmotionCacheProvider } from "tss-react/next/appDir";
import en from "app/_locales/en.json";
import fr from "app/_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 "app/_styles/global.css";
import { LicenseInfo } from "@mui/x-date-pickers-pro";

LicenseInfo.setLicenseKey(
  "7c9bf25d9e240f76e77cbf7d2ba58a23Tz02NjU4OCxFPTE3MTU4NjIzMzQ2ODgsUz1wcm8sTE09c3Vic2NyaXB0aW9uLEtWPTI="
);

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>
  );
};
