import { ApolloProvider } from "@apollo/client";
import { SplitFactory, SplitSdk } from "@splitsoftware/splitio-react";
import { ConfigProvider } from "antd";
import enLocale from "antd/es/locale/en_US";
import moment from "moment";
import React from "react";
import { useTranslation } from "react-i18next";
import GlobalLoadingBar from "../components/global-loading-bar/global-loading-bar.component";
import client from "../utils/GraphQLClient";
import App from "./App";

moment.locale("en-US");

export const factory = SplitSdk({
  core: {
    authorizationKey: process.env.REACT_APP_SPLIT_API,
    key: "anon",
  },
});

export default function AppContainer() {
  const { t } = useTranslation();

  return (
    <ApolloProvider client={client}>
      <ConfigProvider
        //componentSize="small"
        input={{ autoComplete: "new-password" }}
        locale={enLocale}
        theme={{
          token: {
            colorPrimary: "#326ade",
            colorInfo: "#326ade"
          },
        }}
        form={{
          validateMessages: {
            // eslint-disable-next-line no-template-curly-in-string
            required: t("general.validation.required", { label: "${label}" }),
          },
        }}
      >
        <GlobalLoadingBar />
        <SplitFactory factory={factory}>
          <App />
        </SplitFactory>
      </ConfigProvider>
    </ApolloProvider>
  );
}
