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 Login from "./pages/Login";
import Dashboard from "./pages/Dashboard";
import Upload from "./pages/Upload";
import Invoices from "./pages/Invoices";
import InvoicesBAP from "./pages/InvoicesBAP";
import InvoiceDetail from "./pages/InvoiceDetail";
import Settings from "./pages/Settings";
import ImportSettings from "./pages/ImportSettings";
import History from "./pages/History";
import Users from "./pages/Users";
import ListsAdmin from "./pages/ListsAdmin";
import AutomationRules from "./pages/AutomationRules";
import BapHistory from "./pages/BapHistory";
import ImportReport from "./pages/ImportReport";
import LearningSettings from "./pages/LearningSettings";
import VentilationFreePro from "./pages/VentilationFreePro";
import WebImportSources from "./pages/WebImportSources";

function Router() {
  return (
    <Switch>
      <Route path="/" component={Home} />
      <Route path="/login" component={Login} />
      <Route path="/dashboard" component={Dashboard} />
      <Route path="/upload" component={Upload} />
      <Route path="/invoices" component={Invoices} />
      <Route path="/invoices-bap" component={InvoicesBAP} />
      <Route path="/invoices/:id" component={InvoiceDetail} />
      <Route path="/settings" component={Settings} />
      <Route path="/import-settings" component={ImportSettings} />
      <Route path="/history" component={History} />
      <Route path="/users" component={Users} />
      <Route path="/lists-admin" component={ListsAdmin} />
      <Route path="/automation-rules" component={AutomationRules} />
      <Route path="/bap-history" component={BapHistory} />
      <Route path="/import-report" component={ImportReport} />
      <Route path="/learning-settings" component={LearningSettings} />
      <Route path="/ventilation-freepro" component={VentilationFreePro} />
      <Route path="/web-import-sources" component={WebImportSources} />
      <Route path="/404" component={NotFound} />
      <Route component={NotFound} />
    </Switch>
  );
}

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

export default App;
