import _extends from "@babel/runtime/helpers/extends";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useCallback, useState } from 'react';
import useIntersectionObserver from '../../../state/hooks/use-intersection-observer';
import { isIntersectionObserverSupported } from '../../../utils';
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 _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      isIntersected = _useState2[0],
      setIsIntersected = _useState2[1];
    var onIntersecting = useCallback(function () {
      setIsIntersected(true);
    }, []);
    var ref = useIntersectionObserver({
      onIntersecting: onIntersecting
    });
    return /*#__PURE__*/React.createElement(CardLoaderWrapper, {
      appearance: props.appearance,
      ref: ref
    }, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
      isIntersected: isIntersected
    })));
  };
};
var withCardIntersectionObserverFallback = function withCardIntersectionObserverFallback(Component) {
  return function (props) {
    return /*#__PURE__*/React.createElement(CardLoaderWrapper, {
      appearance: props.appearance
    }, /*#__PURE__*/React.createElement(Component, props));
  };
};
export default (function (Component) {
  return isIntersectionObserverSupported() ? withCardIntersectionObserver(Component) : withCardIntersectionObserverFallback(Component);
});