import React from "react";
import { Provider } from "react-redux";
import store from './redux/store';
import ThemeProvider from './theme/ThemeProvider';
import { I18nextProvider, initReactI18next } from "react-i18next";
import i18next from "i18next";
import common_es from "./translations/es/common.json";
import common_en from "./translations/en/common.json";

import AppContainer from "./containers/AppContainer";

import 'antd/dist/antd.css';

export default function App() {

    let lang = sessionStorage.getItem("lang");
    if (!lang) {
        lang = 'es';
    }
    sessionStorage.setItem("lang", lang);

    i18next
    .use(initReactI18next)
    .init({
        interpolation: { escapeValue: false },
        lng: lang,
        resources: {
            es: {
                common: common_es
            },
            en: {
                common: common_en
            }
        },
    });

    return (
        <Provider store={store}>
            <I18nextProvider i18n={i18next}>
                <ThemeProvider mode="default">
                    <AppContainer />
                </ThemeProvider>            
            </I18nextProvider>
        </Provider>
    );
  }
