"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 { LeafcutterProvider } from "@link-stack/leafcutter-ui/components/LeafcutterProvider";
import { AppRouterCacheProvider } from "@mui/material-nextjs/v14-appRouter";
import en from "@link-stack/leafcutter-ui/locales/en.json";
import fr from "@link-stack/leafcutter-ui/locales/fr.json";
import { LicenseInfo } from "@mui/x-license";

LicenseInfo.setLicenseKey(
  "2a7dd73ee59e3e028b96b0d2adee1ad8Tz0xMTMwOTUsRT0xNzc5MDYyMzk5MDAwLFM9cHJvLExNPXN1YnNjcmlwdGlvbixQVj1pbml0aWFsLEtWPTI=",
);

const messages: any = { en, fr };

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

  return (
    <AppRouterCacheProvider>
      <SessionProvider>
        <CookiesProvider>
          <CssBaseline />
          <LeafcutterProvider>
            <LocalizationProvider dateAdapter={AdapterDateFns}>
              <I18n locale={locale} messages={messages[locale]}>
                {children}
              </I18n>
            </LocalizationProvider>
          </LeafcutterProvider>
        </CookiesProvider>
      </SessionProvider>
    </AppRouterCacheProvider>
  );
};
