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";
import * as Sentry from "@sentry/react";

moment.locale("en-US");

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

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

  return (
    <ApolloProvider client={client}>
      <ConfigProvider
        //componentSize="small"
        input={{ autoComplete: "new-password" }}
        locale={enLocale}
        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>
  );
}

export default Sentry.withProfiler(AppContainer);
