import _extends from "@babel/runtime/helpers/extends";
import React, { useCallback } from 'react';
import useIntersectionObserver from '../../../state/hooks/use-intersection-observer';
import { useSmartLinkSeenEvent } from '../../../state/hooks/use-smart-link-seen-event';
import CardLoaderWrapper from '../card-loader-wrapper';
const withCardIntersectionObserver = Component => props => {
  // TODO: NAVX-4682: Add feature parity to LazyIntersectionObserverCard for no lazy loading
  const {
    appearance,
    children,
    id,
    onError: onErrorCallback,
    ui,
    url = ''
  } = props;
  const {
    onIntersecting,
    onStatusSettled
  } = useSmartLinkSeenEvent({
    appearance,
    children,
    id,
    ui,
    url
  });
  const onError = useCallback(data => {
    if (data !== null && data !== void 0 && data.status) {
      onStatusSettled(data.status);
    }
    onErrorCallback === null || onErrorCallback === void 0 ? void 0 : onErrorCallback(data);
  }, [onStatusSettled, onErrorCallback]);
  const ref = useIntersectionObserver({
    onIntersecting
  });
  return /*#__PURE__*/React.createElement(CardLoaderWrapper, {
    appearance: props.appearance,
    ref: ref
  }, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
    onError: onError
  })));
};
export default withCardIntersectionObserver;