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

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