import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import { ConfigProvider } from "./ConfigContext";
import { Layout } from "./Layout";
import { Home } from "./pages/Home";
import { PostPage } from "./pages/PostPage";
import { AdminDashboard, AdminEditor } from "./pages/Admin";

export function App() {
  return (
    <BrowserRouter>
      <ConfigProvider>
        <Routes>
          <Route path="/" element={<Layout />}>
            <Route index element={<Home />} />
            <Route path="post/:slug" element={<PostPage />} />
            <Route path="admin" element={<AdminDashboard />} />
            <Route path="admin/new" element={<AdminEditor />} />
            <Route path="admin/edit/:id" element={<AdminEditor />} />
            <Route path="*" element={<Navigate to="/" replace />} />
          </Route>
        </Routes>
      </ConfigProvider>
    </BrowserRouter>
  );
}
