import { Routes, Route, Navigate } from 'react-router-dom';
import Login from './pages/LoginPage/Index';
import BookingPage from './pages/BookingPage/Index';
import { getItem } from '../src/lib/localStorage';

const Navigates = () => {
  const RequireAuth = ({ children }) => {
    const isAuthenticated = getItem('user') ? true : false;
    return isAuthenticated ? children : <Navigate to="/login" replace />;
  };

  return (
    <Routes>
      <Route path="/login" element={<Login />} />
      <Route
        path="/"
        element={
          <RequireAuth>
            <BookingPage />
          </RequireAuth>
        }
      />
    </Routes>
  );
};

export default Navigates;
