import _extends from "@babel/runtime/helpers/extends";
import React, { useCallback, useState } from 'react';
import useIntersectionObserver from '../../../state/hooks/use-intersection-observer';
import { isIntersectionObserverSupported } from '../../../utils';
import CardLoaderWrapper from '../card-loader-wrapper';
const withCardIntersectionObserver = Component => props => {
  // TODO: NAVX-4682: Add feature parity to LazyIntersectionObserverCard for no lazy loading
  const [isIntersected, setIsIntersected] = useState(false);
  const onIntersecting = useCallback(() => {
    setIsIntersected(true);
  }, []);
  const ref = useIntersectionObserver({
    onIntersecting
  });
  return /*#__PURE__*/React.createElement(CardLoaderWrapper, {
    appearance: props.appearance,
    ref: ref
  }, /*#__PURE__*/React.createElement(Component, _extends({}, props, {
    isIntersected: isIntersected
  })));
};
const withCardIntersectionObserverFallback = Component => props => /*#__PURE__*/React.createElement(CardLoaderWrapper, {
  appearance: props.appearance
}, /*#__PURE__*/React.createElement(Component, props));
export default (Component => isIntersectionObserverSupported() ? withCardIntersectionObserver(Component) : withCardIntersectionObserverFallback(Component));