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 LoginChoice from "./pages/LoginChoice";
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 AdminApprenantDetail from "./pages/AdminApprenantDetail";
import AdminSequenceInscrits from "./pages/AdminSequenceInscrits";
import AdminUsers from "./pages/AdminUsers";
import AdminEmailTemplates from "./pages/AdminEmailTemplates";
import AdminEmailConfig from "./pages/AdminEmailConfig";
import AdminCalendrier from "./pages/AdminCalendrier";
import AdminRappels from "./pages/AdminRappels";
import AdminAnalytics from "./pages/AdminAnalytics";
import AdminEtablissements from "./pages/AdminEtablissements";
import AdminImportExcel from "./pages/AdminImportExcel";
import Inscription from "./pages/Inscription";
import Login from "./pages/Login";

function Router() {
  return (
    <Switch>
      <Route path={"/"} component={LoginChoice} />
      <Route path={"/home"} component={Home} />
      <Route path={"/login"} component={Login} />
      <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/apprenants/:id"} component={AdminApprenantDetail} />
      <Route path={"/admin/sequences/:id/inscrits"} component={AdminSequenceInscrits} />
      <Route path={"/admin/users"} component={AdminUsers} />
      <Route path={"/admin/email-templates"} component={AdminEmailTemplates} />
      <Route path={"/admin/email-config"} component={AdminEmailConfig} />
      <Route path={"/admin/calendrier"} component={AdminCalendrier} />
      <Route path={"/admin/rappels"} component={AdminRappels} />
      <Route path={"/admin/analytics"} component={AdminAnalytics} />
      <Route path={"/admin/etablissements"} component={AdminEtablissements} />
      <Route path={"/admin/import-excel"} component={AdminImportExcel} />
      <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;
