"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/AdapterDateFnsV3";
import { LocalizationProvider } from "@mui/x-date-pickers-pro";
import { AppProvider } from "leafcutter-common/components/AppProvider";
import { NextAppDirEmotionCacheProvider } from "tss-react/next/appDir";
import en from "leafcutter-common/locales/en.json";
import fr from "leafcutter-common/locales/fr.json";
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>
  );
};
