import { Switch, Route, useLocation } from "wouter";
import { queryClient } from "./lib/queryClient";
import { QueryClientProvider } from "@tanstack/react-query";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import NotFound from "@/pages/not-found";
import Home from "@/pages/Home";
import PortfolioPage from "@/pages/Portfolio";
import PaperPortfolio from "@/pages/PaperPortfolio";
import GoldenNiftyStrategy from "@/pages/GoldenNiftyStrategy";
import AlphaShieldStrategy from "@/pages/AlphaShieldStrategy";
import ZerodhaCallback from "@/pages/ZerodhaCallback";
import AdminPage from "@/pages/admin/AdminPage";
import About from "@/pages/About";
import Blog from "@/pages/Blog";
import Privacy from "@/pages/Privacy";
import Terms from "@/pages/Terms";
import Disclosures from "@/pages/Disclosures";
import LearnMore from "@/pages/LearnMore";
import SupportPage from "@/pages/Support";
import ChatWidget from "@/components/chat/ChatWidget";

function Router() {
  return (
    <Switch>
      <Route path="/" component={Home} />
      <Route path="/login" component={ZerodhaCallback} />
      <Route path="/dashboard" component={PortfolioPage} />
      <Route path="/portfolio" component={PortfolioPage} />
      <Route path="/portfolio/paper" component={PaperPortfolio} />
      <Route path="/strategies/golden-nifty" component={GoldenNiftyStrategy} />
      <Route path="/strategies/alpha-shield" component={AlphaShieldStrategy} />
      <Route path="/about" component={About} />
      <Route path="/blog" component={Blog} />
      <Route path="/learn-more" component={LearnMore} />
      <Route path="/privacy" component={Privacy} />
      <Route path="/terms" component={Terms} />
      <Route path="/disclosures" component={Disclosures} />
      <Route path="/support" component={SupportPage} />
      <Route path="/admin" component={AdminPage} />
      <Route path="/admin/users" component={AdminPage} />
      <Route path="/admin/users/:userId" component={AdminPage} />
      <Route path="/admin/runs" component={AdminPage} />
      <Route path="/admin/runs/:runId" component={AdminPage} />
      <Route path="/admin/invariants" component={AdminPage} />
      <Route path="/admin/support-tickets" component={AdminPage} />
      <Route component={NotFound} />
    </Switch>
  );
}

function App() {
  const [location] = useLocation();
  const isAdminRoute = location.startsWith("/admin");

  return (
    <QueryClientProvider client={queryClient}>
      <TooltipProvider>
        <Toaster />
        <Router />
        {!isAdminRoute && <ChatWidget />}
      </TooltipProvider>
    </QueryClientProvider>
  );
}

export default App;
