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 AdminQuestionnaires from "./pages/AdminQuestionnaires";
import AdminQuestionnaireEdit from "./pages/AdminQuestionnaireEdit";
import AdminQuestionnaireAnalyse from "./pages/AdminQuestionnaireAnalyse";
import AdminQuestionnaireSuivi from "./pages/AdminQuestionnaireSuivi";
import AdminRappelsHistorique from "./pages/admin/AdminRappelsHistorique";
import AdminRappelsStats from "./pages/admin/AdminRappelsStats";
import AdminFormateurs from "./pages/admin/AdminFormateurs";
import AdminNotifications from "./pages/admin/AdminNotifications";
import AdminAttestations from "./pages/admin/AdminAttestations";
import HistoriqueAttestations from "./pages/HistoriqueAttestations";
import AdminGestionAttestations from "./pages/AdminGestionAttestations";
import AdminFail2Ban from "./pages/admin/AdminFail2Ban";
import AdminParametres from "./pages/AdminParametres";
import QuestionnaireReponse from "./pages/QuestionnaireReponse";
import Inscription from "./pages/Inscription";
import Login from "./pages/Login";
import FormateurDashboard from "./pages/FormateurDashboard";
import FormateurEmargement from "./pages/FormateurEmargement";
import EmargementScan from "./pages/EmargementScan";
import SignerAttestation from "./pages/SignerAttestation";
import ForgotPassword from "./pages/ForgotPassword";
import ResetPassword from "./pages/ResetPassword";

function Router() {
  return (
    <Switch>
      <Route path={"/"} component={LoginChoice} />
      <Route path={"/home"} component={Home} />
      <Route path={"/login"} component={Login} />
      <Route path={"/forgot-password"} component={ForgotPassword} />
      <Route path={"/reset-password"} component={ResetPassword} />
      <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/formateurs"} component={AdminFormateurs} />
      <Route path={"/admin/notifications"} component={AdminNotifications} />
      <Route path={"/admin/attestations"} component={AdminAttestations} />
      <Route path={"/admin/gestion-attestations"} component={AdminGestionAttestations} />
      <Route path={"/admin/historique-attestations"} component={HistoriqueAttestations} />
      <Route path={"/admin/email-templates"} component={AdminEmailTemplates} />
      <Route path={"/admin/email-config"} component={AdminEmailConfig} />
      <Route path={"/admin/parametres"} component={AdminParametres} />
      <Route path={"/admin/calendrier"} component={AdminCalendrier} />
      <Route path={"/admin/rappels"} component={AdminRappels} />
      <Route path={"/admin/rappels/historique"} component={AdminRappelsHistorique} />
      <Route path={"/admin/rappels/statistiques"} component={AdminRappelsStats} />
      <Route path={"/admin/fail2ban"} component={AdminFail2Ban} />
      <Route path={"/admin/analytics"} component={AdminAnalytics} />
      <Route path={"/admin/etablissements"} component={AdminEtablissements} />
      <Route path={"/admin/import-excel"} component={AdminImportExcel} />
      <Route path={"/admin/questionnaires"} component={AdminQuestionnaires} />
        <Route path="/admin/questionnaires/:id/analyse" component={AdminQuestionnaireAnalyse} />
      <Route path="/admin/questionnaires/suivi" component={AdminQuestionnaireSuivi} />
      <Route path={"/admin/questionnaires/:id"} component={AdminQuestionnaireEdit} />
      <Route path={"/questionnaire/:token"} component={QuestionnaireReponse} />
      <Route path={"/formateur"} component={FormateurDashboard} />
      <Route path={"/formateur/emargement"} component={FormateurEmargement} />
      <Route path={"/emargement/:token"} component={EmargementScan} />
      <Route path={"/signer-attestation/:id"} component={SignerAttestation} />
      <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;
