import { ThemeProvider } from "@/components/theme-provider";
import LayoutMain from "@/pages/Layout";
import { HashRouter as Router, Routes, Route } from "react-router-dom";
import Boot from "@/pages/Boot";
import { Setting } from "./pages/Setting";
import { useEffect } from "react";
import { Models } from "./pages/Models";
import { Tools } from "./pages/Tools";
import { Datasource } from "./pages/Datasource";

function App() {
  const theme = document.querySelector("html")!.getAttribute("theme") as
    | "dark"
    | "light";

  /**
   * 等待渲染完成再显示窗口
   */
  useEffect(() => {
    window.ipcRenderer.send("ipc-loaded");
    return () => {
      window.ipcRenderer.off("ipc-loaded", () => {});
    };
  }, []);

  return (
    <ThemeProvider defaultTheme={theme} storageKey="vite-ui-theme">
      <Router>
        <Routes>
          <Route path="/" element={<LayoutMain />}>
            <Route index element={<Boot />} />
            <Route path="models" element={<Models />} />
            <Route path="datasource" element={<Datasource />} />
            <Route path="tools" element={<Tools />} />
            <Route path="setting" element={<Setting />} />
          </Route>
        </Routes>
      </Router>
    </ThemeProvider>
  );
}

export default App;
