import React, { useState } from "react";
import { Navigate, Route, Routes } from "react-router-dom";
import DashboardPage from "./pages/DashboardPage";
import LoginPage from "./pages/LoginPage";
import ProductPage from "./pages/ProductPage";
import ProtectedRoute from "./components/ProtectedRoute";
import RecoverPasswordPage from "./pages/RecoverPasswordPage";
import RegisterPage from "./pages/RegisterPage";
import ReportsPage from "./pages/ReportsPage";
import TransactionPage from "./pages/TransactionPage";
import WarehousePage from "./pages/WarehousePage";

const App = () => {
  const [user, setUser] = useState(null);

  return (
    <Routes>
      <Route path="/login" element={<LoginPage setUser={setUser} />} />
      <Route path="/register" element={<RegisterPage setUser={setUser} />} />
      <Route path="/recover-password" element={<RecoverPasswordPage />} />
      <Route
        path="/"
        element={
          <ProtectedRoute user={user} setUser={setUser}>
            <DashboardPage user={user} setUser={setUser} />
          </ProtectedRoute>
        }
      />
      <Route
        path="/products"
        element={
          <ProtectedRoute user={user} setUser={setUser}>
            <ProductPage user={user} setUser={setUser} />
          </ProtectedRoute>
        }
      />
      <Route
        path="/warehouses"
        element={
          <ProtectedRoute user={user} setUser={setUser}>
            <WarehousePage user={user} setUser={setUser} />
          </ProtectedRoute>
        }
      />
      <Route
        path="/transactions"
        element={
          <ProtectedRoute user={user} setUser={setUser}>
            <TransactionPage user={user} setUser={setUser} />
          </ProtectedRoute>
        }
      />
      <Route
        path="/reports"
        element={
          <ProtectedRoute user={user} setUser={setUser}>
            <ReportsPage user={user} setUser={setUser} />
          </ProtectedRoute>
        }
      />
      <Route path="*" element={<Navigate to="/" replace />} />
    </Routes>
  );
};

export default App;
