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 MesEtablissements from "./pages/MesEtablissements";
import MesDemandes from "./pages/MesDemandes";
import FicheEtablissement from "./pages/FicheEtablissement";
import Admin from "./pages/Admin";
import Login from "./pages/Login";
import LoginLocal from "./pages/LoginLocal";
import MesSolutions from "./pages/MesSolutions";
import SolutionsLogicielles from "./pages/SolutionsLogicielles";
import Statistiques from "./pages/Statistiques";

function Router() {
  return (
    <Switch>
      {/* Pages publiques de connexion */}
      <Route path="/login" component={Login} />
      <Route path="/login/local" component={LoginLocal} />

      {/* Pages applicatives (nécessitent une connexion) */}
      <Route path="/" component={Home} />
      <Route path="/mes-etablissements" component={MesEtablissements} />
      <Route path="/mes-demandes" component={MesDemandes} />
      <Route path="/etablissement/:id" component={FicheEtablissement} />
      <Route path="/admin" component={Admin} />
      <Route path="/mes-solutions" component={MesSolutions} />
      <Route path="/solutions" component={SolutionsLogicielles} />
      <Route path="/statistiques" component={Statistiques} />

      {/* Fallback */}
      <Route path="/404" component={NotFound} />
      <Route component={NotFound} />
    </Switch>
  );
}

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

export default App;
