/**
 * This file is the entry point for the React app, it sets up the root
 * element and renders the App component to the DOM.
 *
 * It is included in `src/index.html`.
 */

import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { App, ConfigProvider, Empty, theme } from "antd";
import zhCN from 'antd/locale/zh_CN';
import { RouterProvider } from "react-router";
import { LogtoProvider, type LogtoConfig } from '@logto/react';
import { route } from "./routes";
import { LOGTO_RESOURCE } from "./utils/constants";
import { LOGTO_APPID, LOGTO_DOMAIN } from "./utils/common";

const elem = document.getElementById("root")!;

const config: LogtoConfig = {
  endpoint: LOGTO_DOMAIN,
  appId: LOGTO_APPID,
  resources: [LOGTO_RESOURCE],
  scopes: [
    'admin',	
  ]
};
const app = (
  <StrictMode>
    <ConfigProvider
      theme={{ algorithm: theme.darkAlgorithm }}
      locale={zhCN}
      renderEmpty={() => <Empty description={'暂无数据'} />}
    >
      <App>
        <LogtoProvider config={config}>
          <RouterProvider router={route} />
        </LogtoProvider>
      </App>
    </ConfigProvider>
  </StrictMode>
);

if (import.meta.hot) {
  // With hot module reloading, `import.meta.hot.data` is persisted.
  const root = (import.meta.hot.data.root ??= createRoot(elem));
  root.render(app);
} else {
  // The hot module reloading API is not available in production.
  createRoot(elem).render(app);
}
