import React from "react";
import { Routes, Route, Navigate, useLocation } from "react-router-dom";
import Layout from "./Layout";
import Dashboard from "./pages/Dashboard";
import History from "./pages/History";

function RoutedApp() {
  const location = useLocation();
  const path = location.pathname;

  let currentPageName = "Dashboard";
  if (path.startsWith("/history")) currentPageName = "History";

  return (
    <Layout currentPageName={currentPageName}>
      <Routes>
        <Route path="/" element={<Navigate to="/dashboard" replace />} />
        <Route path="/dashboard" element={<Dashboard />} />
        <Route path="/history" element={<History />} />
      </Routes>
    </Layout>
  );
}

export default function App() {
  return <RoutedApp />;
}
