  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 Student from "./pages/Student";
   import Payments from "./pages/Payments";
   import Fees from "./pages/Fees";
   import Record from "./pages/Records";


   const ProtectedRoute = ({ children }) => {
  if (!localStorage.getItem('token')) {
    return <Navigate to="/login" />
  }
  return children
}


 function App(){
    return(
        <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="/student" element={ <ProtectedRoute><Student/></ProtectedRoute>} />
        <Route path="/payments" element={ <ProtectedRoute><Payments/></ProtectedRoute>} />
        <Route path="/fees" element={ <ProtectedRoute><Fees/></ProtectedRoute>} />
        <Route path="/records" element={ <ProtectedRoute><Record/></ProtectedRoute>} />
        </Routes>
        </BrowserRouter>
    )
 }

 export default App