import { ApolloProvider } from "@apollo/client";
//import trackerRedux from "@openreplay/tracker-redux";
import Tracker from "@openreplay/tracker";
import trackerGraphQL from "@openreplay/tracker-graphql";
import { SplitFactory, SplitSdk } from "@splitsoftware/splitio-react";
import { ConfigProvider } from "antd";
import enLocale from "antd/es/locale/en_US";
import LogRocket from "logrocket";
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 trackerAssist from "@openreplay/tracker-assist";
import { getCurrentUser } from "../firebase/firebase.utils";
import client from "../utils/GraphQLClient";
import App from "./App";

moment.locale("en-US");

export const tracker = new Tracker({
  projectKey: "trDmOZlEXUpjGsMtHroA",
  ingestPoint: "https://replay.imex.online/ingest",
  ...(process.env.NODE_ENV === null || process.env.NODE_ENV === "development"
    ? { __DISABLE_SECURE_MODE: true }
    : {}),
  // beaconSize: 10485760,
  onStart: async ({ sessionID }) => {
    const user = await getCurrentUser();
    if (user) tracker.setUserID(user.email);
    console.log("ORS SESSION ", sessionID, user && user.email);
  },
});

// tracker.use(
//   trackerAssist({ confirmText: "Technical support is about to assist you." })
// ); // check the list of available options below
export const recordGraphQL = tracker.use(trackerGraphQL());
tracker.start();
if (process.env.NODE_ENV === "production") LogRocket.init("gvfvfw/bodyshopapp");

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