"use client";

import { FC, PropsWithChildren } from "react";
import { CssBaseline } from "@mui/material";
import { CookiesProvider } from "react-cookie";
import { SessionProvider } from "next-auth/react";
import { I18n } from "react-polyglot";
import { AdapterDateFns } from "@mui/x-date-pickers-pro/AdapterDateFnsV3";
import { LocalizationProvider } from "@mui/x-date-pickers-pro";
import { LicenseInfo } from "@mui/x-license";
import { locales, LeafcutterProvider } from "@link-stack/leafcutter-ui";
import { ZammadLoginProvider } from "./ZammadLoginProvider";

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

export const MultiProvider: FC<PropsWithChildren> = ({ children }) => {
  const messages: any = { en: locales.en, fr: locales.fr };
  const locale = "en";

  return (
    <SessionProvider basePath="/link/api/auth">
      <CssBaseline />
      <ZammadLoginProvider>
        <CookiesProvider>
          <LocalizationProvider dateAdapter={AdapterDateFns}>
            <I18n locale={locale} messages={messages[locale]}>
              <LeafcutterProvider>{children}</LeafcutterProvider>
            </I18n>
          </LocalizationProvider>
        </CookiesProvider>
      </ZammadLoginProvider>
    </SessionProvider>
  );
};
