import { Toaster as Sonner } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
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/home/ScrollToTop";
import ManageProject from "./components/admin/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 Technologies from "./pages/Technologies";
import { QueryProvider } from "./provider/QueryProvider";
import OverviewPage from "./components/admin/dashboards/OverviewPage";
import { ThemeProvider } from "./provider/ThemeProvider";

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="technologies" element={<Technologies />} />
          {/* <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;
