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';
var withCardIntersectionObserver = function withCardIntersectionObserver(Component) {
  return function (props) {
    // TODO: NAVX-4682: Add feature parity to LazyIntersectionObserverCard for no lazy loading
    var appearance = props.appearance,
      children = props.children,
      id = props.id,
      onErrorCallback = props.onError,
      ui = props.ui,
      _props$url = props.url,
      url = _props$url === void 0 ? '' : _props$url;
    var _useSmartLinkSeenEven = useSmartLinkSeenEvent({
        appearance: appearance,
        children: children,
        id: id,
        ui: ui,
        url: url
      }),
      onIntersecting = _useSmartLinkSeenEven.onIntersecting,
      onStatusSettled = _useSmartLinkSeenEven.onStatusSettled;
    var onError = useCallback(function (data) {
      if (data !== null && data !== void 0 && data.status) {
        onStatusSettled(data.status);
      }
      onErrorCallback === null || onErrorCallback === void 0 || onErrorCallback(data);
    }, [onStatusSettled, onErrorCallback]);
    var ref = useIntersectionObserver({
      onIntersecting: onIntersecting
    });
    return /*#__PURE__*/React.createElement(CardLoaderWrapper, {
      appearance: props.appearance,
      ref: ref
    }, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
      onError: onError
    })));
  };
};
export default withCardIntersectionObserver;