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 ErrorBoundary from "@/components/ErrorBoundary";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Index from "./pages/Index";
import InteractiveIndex from "./components/InteractiveIndex";
import Themes from "./pages/Themes";
import About from "./pages/About";
import DiscreteMath from "./pages/theme-pages/DiscreteMath";
import SocialChoice from "./pages/theme-pages/SocialChoice";
import AdvancedAlgorithms from "./pages/theme-pages/AdvancedAlgorithms";
import DataStructures from "./pages/theme-pages/DataStructures";
import Games from "./pages/theme-pages/Games";
import CardsMath from "./pages/theme-pages/CardsMath";
import Puzzles from "./pages/theme-pages/Puzzles";
import Miscellany from "./pages/theme-pages/Miscellany";
import ContestProblems from "./pages/theme-pages/ContestProblems";
import BinaryNumberGamePage from "./pages/BinaryNumberGamePage";
import BinaryNumberGameGreenScreen from "./pages/BinaryNumberGameGreenScreen";
import TernaryNumberGamePage from "./pages/TernaryNumberGamePage";
import BalancedTernaryGamePage from "./pages/BalancedTernaryGamePage";
import BinarySearchTrickPage from "./pages/BinarySearchTrickPage";
import BinarySearchTrickGreenScreen from "./pages/BinarySearchTrickGreenScreen";
import GameOfSimGreenScreen from "./pages/GameOfSimGreenScreen";
import GameOfSimPage from "./pages/GameOfSimPage";
import TernarySearchTrickPage from "./pages/TernarySearchTrickPage";
import TernarySearchTrickGreenScreen from "./pages/TernarySearchTrickGreenScreen";
import NorthcottsGamePage from "./pages/NorthcottsGamePage";
import KnightsPuzzlePage from "./pages/KnightsPuzzlePage";
import NimGamePage from "./pages/NimGamePage";
import AssistedNimGamePage from "./pages/AssistedNimGamePage";
import GoldCoinGamePage from "./pages/GoldCoinGamePage";
import PlateSwapPuzzlePage from "./pages/PlateSwapPuzzlePage";
import ChessboardRepaintPuzzlePage from "./pages/ChessboardRepaintPuzzlePage";
import ZeckendorfGamePage from "./pages/ZeckendorfGamePage";
import ZeckendorfSearchTrickPage from "./pages/ZeckendorfSearchTrickPage";
import GuessingGamePage from "./pages/GuessingGamePage";
import Foundations from "./pages/theme-pages/discrete-math/Foundations";
import Proofs from "./pages/theme-pages/discrete-math/Proofs";
import Counting from "./pages/theme-pages/discrete-math/Counting";
import Uncertainty from "./pages/theme-pages/discrete-math/Uncertainty";
import Structures from "./pages/theme-pages/discrete-math/Structures";
import Numbers from "./pages/theme-pages/discrete-math/Numbers";
import Graphs from "./pages/theme-pages/discrete-math/Graphs";
import NotFound from "./pages/NotFound";
import GridTilingPuzzlePage from './pages/GridTilingPuzzlePage';
import SunnyLinesPuzzlePage from './pages/SunnyLinesPuzzlePage';
import SikiniaParliamentPuzzlePage from './pages/SikiniaParliamentPuzzlePage';
import NQueensPuzzlePage from './pages/NQueensPuzzlePage';
import RulesOfInferencePlaygroundPage from './pages/RulesOfInferencePlaygroundPage';

const queryClient = new QueryClient();

const App = () => (
  <ErrorBoundary>
    <QueryClientProvider client={queryClient}>
      <TooltipProvider>
        <Toaster />
        <Sonner />
        <BrowserRouter>
        <Routes>
          <Route path="/" element={<Index />} />
          <Route path="/index" element={<InteractiveIndex />} />
          <Route path="/themes" element={<Themes />} />
          <Route path="/about" element={<About />} />
          
          {/* Theme-specific routes */}
          <Route path="/themes/discrete-math" element={<DiscreteMath />} />
          <Route path="/themes/discrete-math/foundations" element={<Foundations />} />
          <Route path="/themes/discrete-math/proofs" element={<Proofs />} />
          <Route path="/themes/discrete-math/counting" element={<Counting />} />
          <Route path="/themes/discrete-math/uncertainty" element={<Uncertainty />} />
          <Route path="/themes/discrete-math/structures" element={<Structures />} />
          <Route path="/themes/discrete-math/numbers" element={<Numbers />} />
          <Route path="/themes/discrete-math/graphs" element={<Graphs />} />
          <Route path="/themes/social-choice" element={<SocialChoice />} />
          <Route path="/themes/advanced-algorithms" element={<AdvancedAlgorithms />} />
          <Route path="/themes/data-structures" element={<DataStructures />} />
          <Route path="/themes/games" element={<Games />} />
          <Route path="/themes/cards-math" element={<CardsMath />} />
          <Route path="/themes/puzzles" element={<Puzzles />} />
          <Route path="/themes/miscellany" element={<Miscellany />} />
          <Route path="/themes/contest-problems" element={<ContestProblems />} />
          <Route path="/contest-problems/grid-tiling" element={<GridTilingPuzzlePage />} />
          <Route path="/contest-problems/sunny-lines" element={<SunnyLinesPuzzlePage />} />
          
          {/* Direct interactive routes */}
          <Route path="/binary-number-game" element={<BinaryNumberGamePage />} />
          <Route path="/binary-number-game/:mode" element={<BinaryNumberGameGreenScreen />} />
          <Route path="/ternary-number-game" element={<TernaryNumberGamePage />} />
          <Route path="/balanced-ternary-game" element={<BalancedTernaryGamePage />} />
          <Route path="/binary-search-trick" element={<BinarySearchTrickPage />} />
          <Route path="/binary-search-trick/:mode" element={<BinarySearchTrickGreenScreen />} />
          <Route path="/game-of-sim" element={<GameOfSimPage />} />
          <Route path="/game-of-sim/:mode" element={<GameOfSimGreenScreen />} />
          <Route path="/ternary-search-trick" element={<TernarySearchTrickPage />} />
          <Route path="/ternary-search-trick/:mode" element={<TernarySearchTrickGreenScreen />} />
          <Route path="/northcotts-game" element={<NorthcottsGamePage />} />
          <Route path="/knights-puzzle" element={<KnightsPuzzlePage />} />
          <Route path="/games/nim" element={<NimGamePage />} />
          <Route path="/games/assisted-nim" element={<AssistedNimGamePage />} />
                  <Route path="/games/gold-coin" element={<GoldCoinGamePage />} />
        <Route path="/puzzles/sikinia-parliament" element={<SikiniaParliamentPuzzlePage />} />
        <Route path="/puzzles/plate-swap" element={<PlateSwapPuzzlePage />} />
        <Route path="/puzzles/chessboard-repaint" element={<ChessboardRepaintPuzzlePage />} />
        <Route path="/puzzles/n-queens" element={<NQueensPuzzlePage />} />
        <Route path="/discrete-math/foundations/zeckendorf" element={<ZeckendorfGamePage />} />
        <Route path="/discrete-math/foundations/zeckendorf-search" element={<ZeckendorfSearchTrickPage />} />
        <Route path="/discrete-math/foundations/rules-of-inference" element={<RulesOfInferencePlaygroundPage />} />
        <Route path="/guessing-game" element={<GuessingGamePage />} />
          
          {/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
          <Route path="*" element={<NotFound />} />
        </Routes>
        </BrowserRouter>
      </TooltipProvider>
    </QueryClientProvider>
  </ErrorBoundary>
);

export default App;
