import { DomainServiceProvider } from "./context/domainService";
import { defaultLang, theme } from "./constant";
import { useTracker } from "./hook/useTracker";
import { RouterElements } from "./router";
import { ConfigProvider, App as AntApp } from "antd";
import { useI18n } from "@tavi/i18n";
import "./styles/app.less";
import { useEffect } from "react";
import { antdUtils } from "./AntdUtils";

/**
 * 国际化
 */
export const { i18n } = useI18n({
  loadPath: "/locales/{{lng}}/{{ns}}.json",
  fallbackLng: defaultLang,
  debug: false,
});

export const App = () => {
  useTracker();
  const { notification, message, modal } = AntApp.useApp();
  useEffect(() => {
    antdUtils
      .setMessageInstance(message)
      .setModalInstance(modal)
      .setNotificationInstance(notification);
  }, []);

  return (
    <DomainServiceProvider>
      <ConfigProvider theme={theme}>
        <RouterElements />
      </ConfigProvider>
    </DomainServiceProvider>
  );
};
