import { Navigate } from 'react-router-dom';

interface ProtectedRouteProps {
  children: JSX.Element;
}

const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
  // Check if user is logged in (from localStorage or context)
  const user = localStorage.getItem('sp_user');
  
  if (!user) {
    // If not logged in, redirect to login page
    return <Navigate to="/login" replace />;
  }

  // Else render the protected component
  return children;
};

export default ProtectedRoute;
