  import React from "react";
 import { BrowserRouter,Routes,Route } from "react-router-dom";
 import Navbar from "./components/Navbar";
 import Login from "./pages/Login";
import Register from "./pages/Register";
import Dashboard from "./pages/Dashboard";
import Warehouse from "./pages/Warehouse";
import Product from "./pages/Product";
import StockTransaction from "./pages/StockTransaction";
import Reports from "./pages/Reports";


 function App () {
  const ProtectedRoute = ({ children }) => {
  if (!localStorage.getItem('token')) {
    return <Navigate to="/login" />
  }
  return children
}
  return(
    <div>
      <BrowserRouter>
      <Navbar/>
      <Routes>
        <Route path="/" element={<Login/>} />
        <Route path="/login" element={<Login/>}  />
        <Route path="/register" element={<Register/>}  />
        <Route path="/dashboard" element={<ProtectedRoute><Dashboard/></ProtectedRoute>} />
        <Route path="/product" element={<ProtectedRoute><Product/></ProtectedRoute>} />
        <Route path="/warehouse" element={<ProtectedRoute><Warehouse/></ProtectedRoute>} />
        <Route path="/stockTransaction" element={<ProtectedRoute><StockTransaction/></ProtectedRoute>} />
        <Route path="/reports" element={<ProtectedRoute><Reports/></ProtectedRoute>}  />

      
      </Routes>
      </BrowserRouter>

    </div>
  )
 }
 export default App