import  { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchAdminUser } from '../../redux/features/adminSlice';

const AdminDetails = () => {
  const dispatch = useDispatch();
  const { user, loading, error } = useSelector((state) => state.admin);
  console.log("user", user)

  useEffect(() => {
    dispatch(fetchAdminUser());
  }, [dispatch]);

  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error: {error}</p>;

  return (
    <div>
      <h2>Admin Details</h2>
      {user ? (
        <div>
          <p><strong>Username:</strong> {user.username}</p>
          {/* Add other fields here if available in the response */}
        </div>
      ) : (
        <p>No user details found. Thank you</p>
      )}
    </div>
  );
};

export default AdminDetails;
