import { createRoot } from "react-dom/client";
import { BrowserRouter } from "react-router-dom";
import { initReactI18next } from "react-i18next";
import i18n from "i18next";
import { getLanguage } from "taehui-ts/language";

import { Stores } from "src/Stores";
import TaehuiView from "src/taehui/TaehuiView";

import Language from "src/Language.json";

import "bootstrap/dist/css/bootstrap.min.css";
import "react-contexify/dist/ReactContexify.css";
import "react-toastify/dist/ReactToastify.css";
import "src/index.scss";

(async () => {
  await i18n.use(initReactI18next).init({
    resources: Language,
    lng: "ko-KR",
  });

  const language = getLanguage();
  await i18n.changeLanguage(language);

  const root = document.getElementById("root");
  if (root) {
    createRoot(root).render(
      <Stores>
        <BrowserRouter>
          <TaehuiView />
        </BrowserRouter>
      </Stores>,
    );
  }
})();
