import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { Toaster as Sonner } from "@/components/ui/sonner";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import { LocaleProvider } from "@/i18n/LocaleContext";
import { ROUTES } from "@/i18n/routes";
import { SiteLayout } from "@/components/layout/SiteLayout";
import Index from "./pages/Index";
import Municipality from "./pages/Municipality";
import Community from "./pages/Community";
import LocalBusinesses from "./pages/LocalBusinesses";
import Events from "./pages/Events";
import Mayor from "./pages/Mayor";
import Council from "./pages/Council";
import Services from "./pages/Services";
import Documents from "./pages/Documents";
import CommunityPhotos from "./pages/CommunityPhotos";
import ActivitiesPhotos from "./pages/ActivitiesPhotos";
import DevelopmentPlan from "./pages/DevelopmentPlan";
import TownMap from "./pages/TownMap";
import PublicNotices from "./pages/PublicNotices";
import Minutes from "./pages/Minutes";
import Newsletters from "./pages/Newsletters";
import NotFound from "./pages/NotFound";

const queryClient = new QueryClient();

const App = () => (
  <QueryClientProvider client={queryClient}>
    <TooltipProvider>
      <Toaster />
      <Sonner />
      <BrowserRouter>
        <LocaleProvider>
          <SiteLayout>
            <Routes>
              {/* French (canonical) */}
              <Route path={ROUTES.home.fr} element={<Index />} />
              <Route path={ROUTES.municipality.fr} element={<Municipality />} />
              <Route path={ROUTES.mayor.fr} element={<Mayor />} />
              <Route path={ROUTES.council.fr} element={<Council />} />
              <Route path={ROUTES.services.fr} element={<Services />} />
              <Route path={ROUTES.documents.fr} element={<Documents />} />
              <Route path={ROUTES.community.fr} element={<Community />} />
              <Route path={ROUTES.communityPhotos.fr} element={<CommunityPhotos />} />
              <Route path={ROUTES.activitiesPhotos.fr} element={<ActivitiesPhotos />} />
              <Route path={ROUTES.developmentPlan.fr} element={<DevelopmentPlan />} />
              <Route path={ROUTES.townMap.fr} element={<TownMap />} />
              <Route path={ROUTES.businesses.fr} element={<LocalBusinesses />} />
              <Route path={ROUTES.events.fr} element={<Events />} />
              <Route path={ROUTES.publicNotices.fr} element={<PublicNotices />} />
              <Route path={ROUTES.minutes.fr} element={<Minutes />} />
              <Route path={ROUTES.newsletters.fr} element={<Newsletters />} />

              {/* English */}
              <Route path={ROUTES.home.en} element={<Index />} />
              <Route path={ROUTES.municipality.en} element={<Municipality />} />
              <Route path={ROUTES.mayor.en} element={<Mayor />} />
              <Route path={ROUTES.council.en} element={<Council />} />
              <Route path={ROUTES.services.en} element={<Services />} />
              <Route path={ROUTES.documents.en} element={<Documents />} />
              <Route path={ROUTES.community.en} element={<Community />} />
              <Route path={ROUTES.communityPhotos.en} element={<CommunityPhotos />} />
              <Route path={ROUTES.activitiesPhotos.en} element={<ActivitiesPhotos />} />
              <Route path={ROUTES.developmentPlan.en} element={<DevelopmentPlan />} />
              <Route path={ROUTES.townMap.en} element={<TownMap />} />
              <Route path={ROUTES.businesses.en} element={<LocalBusinesses />} />
              <Route path={ROUTES.events.en} element={<Events />} />
              <Route path={ROUTES.publicNotices.en} element={<PublicNotices />} />
              <Route path={ROUTES.minutes.en} element={<Minutes />} />
              <Route path={ROUTES.newsletters.en} element={<Newsletters />} />

              {/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
              <Route path="*" element={<NotFound />} />
            </Routes>
          </SiteLayout>
        </LocaleProvider>
      </BrowserRouter>
    </TooltipProvider>
  </QueryClientProvider>
);

export default App;
