import { Toaster } from "@/components/ui/toaster";
import { Toaster as Sonner } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import { ThemeProvider } from "next-themes";
import NotFound from "./pages/NotFound";
import Redirect from "./pages/Redirect";
import React from "react";
import CommanderApp from "./modules/commander/App";
import IntelligenceIAApp from "./modules/intelligence-ia/App";
import IntelligenceScoreApp from "./modules/intelligence-score/App";

const queryClient = new QueryClient();

const App = () => (
  <QueryClientProvider client={queryClient}>
    <ThemeProvider
      attribute="class"
      defaultTheme="light"
      themes={["light", "dark"]}
      enableSystem={false}
      storageKey="hgtx-commander-theme"
      enableColorScheme
    >
      <TooltipProvider>
        <Toaster />
        <Sonner />
        <BrowserRouter>
          <Routes>
            <Route path="/redir/:gsikey" element={<Redirect />} />

            <Route path="/commander/*" element={<CommanderApp />} />
            <Route path="/intelligence-ia/*" element={<IntelligenceIAApp />} />
            <Route path="/intelligence-score/*" element={<IntelligenceScoreApp />} />

            <Route path="/" element={<Navigate to="/commander" replace />} />
            <Route path="/404" element={<NotFound />} />
            <Route path="*" element={<NotFound />} />
          </Routes>
        </BrowserRouter>
      </TooltipProvider>
    </ThemeProvider>
  </QueryClientProvider>
);

export default App;

const HGTXLogin = () => {
  React.useEffect(() => {
    window.location.replace(import.meta.env.VITE_BASE_URL_HGTX_CORE);
  });

  return <></>;
};
