import { Toaster } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import NotFound from "@/pages/NotFound";
import { Route, Switch } from "wouter";
import ErrorBoundary from "./components/ErrorBoundary";
import { ThemeProvider } from "./contexts/ThemeContext";
import Home from "./pages/Home";
import AdminRapportPublicCible from "./pages/AdminRapportPublicCible";
import Admin from "./pages/Admin";
import AdminFormations from "./pages/AdminFormations";
import AdminSequences from "./pages/AdminSequences";
import AdminApprenants from "./pages/AdminApprenants";
import AdminSequenceInscrits from "./pages/AdminSequenceInscrits";
import AdminUsers from "./pages/AdminUsers";
import AdminEmailTemplates from "./pages/AdminEmailTemplates";
import Inscription from "./pages/Inscription";

function Router() {
  return (
    <Switch>
      <Route path={"/"} component={Home} />
      <Route path={"/admin/rapport-public-cible"} component={AdminRapportPublicCible} />
      <Route path={"/inscription/:lien"} component={Inscription} />
      <Route path={"/admin"} component={Admin} />
      <Route path={"/admin/formations"} component={AdminFormations} />
      <Route path={"/admin/sequences"} component={AdminSequences} />
      <Route path={"/admin/apprenants"} component={AdminApprenants} />
      <Route path={"/admin/sequences/:id/inscrits"} component={AdminSequenceInscrits} />
      <Route path={"/admin/users"} component={AdminUsers} />
      <Route path={"/admin/email-templates"} component={AdminEmailTemplates} />
      <Route path={"/404"} component={NotFound} />
      {/* Final fallback route */}
      <Route component={NotFound} />
    </Switch>
  );
}

function App() {
  return (
    <ErrorBoundary>
      <ThemeProvider defaultTheme="light">
        <TooltipProvider>
          <Toaster />
          <Router />
        </TooltipProvider>
      </ThemeProvider>
    </ErrorBoundary>
  );
}

export default App;
