import React, { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom'; // to navigate after logging out

const Logout = () => {
  const [loading, setLoading] = useState(true);
  const navigate = useNavigate();

  useEffect(() => {
    // Simulate logout by clearing the session or token
    const logoutUser = () => {
      // Clear any authentication data
      localStorage.removeItem('authToken'); // or sessionStorage
      sessionStorage.removeItem('userData'); // if applicable

      // Redirect to login page or home
      navigate('/login'); // Redirecting to login page after logout
    };

    logoutUser();
    setLoading(false);
  }, [navigate]);

  return (
    <div>
      {loading ? (
        <p>Logging out...</p>
      ) : (
        <p>You have been logged out successfully.</p>
      )}
    </div>
  );
};

export default Logout;
