import { Toaster } from "@/components/ui/toaster";
import { Toaster as Sonner } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { HelmetProvider } from "react-helmet-async";
import Index from "./pages/Index";
import Demo from "./pages/Demo";
import Pricing from "./pages/Pricing";
import Signup from "./pages/Signup";
import SignupThankYou from "./pages/SignupThankYou";
import Login from "./pages/Login";
import Privacy from "./pages/Privacy";
import Terms from "./pages/Terms";
import NotFound from "./pages/NotFound";
import FAQ from "./pages/FAQ";
import Contact from "./pages/Contact";
import Features from "./pages/Features";
import Problems from "./pages/Problems";
import ProblemDetail from "./pages/ProblemDetail";
import Partners from "./pages/Partners";
import AgencyPartners from "./pages/AgencyPartners";
import Affiliate from "./pages/Affiliate";
import AdminDemoRequest from "./pages/AdminDemoRequest";
import Blog from "./pages/Blog";
import BlogPost from "./pages/BlogPost";
import CookieConsent from "./components/CookieConsent";
import { usePartnerCode } from "./hooks/use-partner-code";

const queryClient = new QueryClient();

/** Captures ?partnerCode=XXX on any route and stores it in a cookie. */
const PartnerCodeCapture = () => { usePartnerCode(); return null; };

const App = () => (
  <HelmetProvider>
  <QueryClientProvider client={queryClient}>
    <TooltipProvider>
      <Toaster />
      <Sonner />
      <BrowserRouter>
        <PartnerCodeCapture />
        <Routes>
          <Route path="/" element={<Index />} />
          <Route path="/demo" element={<Demo />} />
          <Route path="/demo/admin-request" element={<AdminDemoRequest />} />
          <Route path="/features" element={<Features />} />
          <Route path="/pricing" element={<Pricing />} />
          <Route path="/signup" element={<Signup />} />
          <Route path="/signup/thank-you" element={<SignupThankYou />} />
          <Route path="/thankyou" element={<SignupThankYou />} />
          <Route path="/login" element={<Login />} />
          <Route path="/privacy" element={<Privacy />} />
          <Route path="/terms" element={<Terms />} />
          <Route path="/faq" element={<FAQ />} />
          <Route path="/contact" element={<Contact />} />
          <Route path="/problems" element={<Problems />} />
          <Route path="/problems/:slug" element={<ProblemDetail />} />
          <Route path="/partners" element={<Partners />} />
          <Route path="/partners/agency" element={<AgencyPartners />} />
          <Route path="/partners/affiliate" element={<Affiliate />} />
          <Route path="/blog" element={<Blog />} />
          <Route path="/blog/:slug" element={<BlogPost />} />
          {/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
          <Route path="*" element={<NotFound />} />
        </Routes>
        <CookieConsent />
      </BrowserRouter>
    </TooltipProvider>
  </QueryClientProvider>
  </HelmetProvider>
);

export default App;
