import { useCallback, useEffect, useState } from 'react';
import { isAmityAd } from './useCustomRankingGlobalFeed';
import AdEngine from '../../core/engines/AdEngine';
export const usePostImpression = postList => {
  const [postViews, setPostViews] = useState([]);
  const handleViewChange = useCallback(({
    viewableItems
  }) => {
    setPostViews([...viewableItems]);
  }, []);
  useEffect(() => {
    if (postViews.length > 0) {
      for (const viewablePost of postViews) {
        if (viewablePost) {
          const post = postList === null || postList === void 0 ? void 0 : postList.find(post => isAmityAd(post) ? post.adId === viewablePost.item.adId : post.postId === viewablePost.item.postId);
          if (post && isAmityAd(post)) {
            AdEngine.instance.markSeen(post, 'feed');
          }
          if (post && !isAmityAd(post)) {
            post.analytics.markAsViewed();
          }
        }
      }
    }
  }, [postViews, postList]);
  return {
    handleViewChange
  };
};
//# sourceMappingURL=usePostImpression.js.map