"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _useIntersectionObserver = _interopRequireDefault(require("../../../state/hooks/use-intersection-observer"));
var _useSmartLinkSeenEvent = require("../../../state/hooks/use-smart-link-seen-event");
var _cardLoaderWrapper = _interopRequireDefault(require("../card-loader-wrapper"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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 = (0, _useSmartLinkSeenEvent.useSmartLinkSeenEvent)({
        appearance: appearance,
        children: children,
        id: id,
        ui: ui,
        url: url
      }),
      onIntersecting = _useSmartLinkSeenEven.onIntersecting,
      onStatusSettled = _useSmartLinkSeenEven.onStatusSettled;
    var onError = (0, _react.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 = (0, _useIntersectionObserver.default)({
      onIntersecting: onIntersecting
    });
    return /*#__PURE__*/_react.default.createElement(_cardLoaderWrapper.default, {
      appearance: props.appearance,
      ref: ref
    }, /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, props, {
      onError: onError
    })));
  };
};
var _default = exports.default = withCardIntersectionObserver;