import { Toaster as Sonner } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import { ThemeProvider } from "@/contexts/ThemeContext";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { AnimatePresence } from "framer-motion";
import { BrowserRouter, Route, Routes, useLocation } from "react-router-dom";
import ScrollToTop from "./components/ScrollToTop";
import OverviewPage from "./pages/admins/components/dashboards/OverviewPage";
import ManageProject from "./pages/admins/components/projects/ManageProject";
import DashboardLayout from "./pages/admins/layout/DashboardLayout";
import MainLayout from "./pages/admins/layout/MainLayout";
import Index from "./pages/Index";
import NotFound from "./pages/NotFound";
import { PrivacyPolicy } from "./pages/PrivacyPolicy";
import ProjectDetails from "./pages/ProjectDetails";
import Projects from "./pages/Projects";
import { QueryProvider } from "./provider/QueryProvider";

function AnimatedRoutes() {
  const location = useLocation();

  return (
    <AnimatePresence mode="wait">
      <Routes location={location} key={location.pathname}>
        {/* main layouts */}
        <Route element={<MainLayout />}>
          <Route path="/" element={<Index />} />
          <Route path="/projects" element={<Projects />} />
          <Route path="/projects/:id" element={<ProjectDetails />} />
          {/* <Route path="/blog" element={<Blog />} />
        <Route path="/blog/:id" element={<BlogArticle />} /> */}
          {/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
          <Route path="/privacy" element={<PrivacyPolicy />} />
        </Route>
        {/* dashboard layouts */}
        <Route path="/dashboard" element={<DashboardLayout />}>
          <Route index element={<OverviewPage />} />
          <Route path="/dashboard/projects" element={<ManageProject />} />
          {/* <Route path="users" element={<Users />} />
    <Route path="settings" element={<Settings />} /> */}
        </Route>
        <Route path="*" element={<NotFound />} />
      </Routes>
    </AnimatePresence>
  );
}

const App = () => (
  <QueryProvider>
    <ReactQueryDevtools initialIsOpen={false} />
    <ThemeProvider>
      <TooltipProvider>
        <Sonner />
        <BrowserRouter>
          <ScrollToTop />
          <AnimatedRoutes />
        </BrowserRouter>
      </TooltipProvider>
    </ThemeProvider>
  </QueryProvider>
);

export default App;
