"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(
  "c787ac6613c5f2aa0494c4285fe3e9f2Tz04OTY1NyxFPTE3NDYzNDE0ODkwMDAsUz1wcm8sTE09c3Vic2NyaXB0aW9uLEtWPTI=",
);

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