"use strict";

exports.__esModule = true;
exports.renderWithContext = void 0;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react2 = require("@testing-library/react");
var _has = _interopRequireDefault(require("lodash/fp/has"));
var _translate = require("@coorpacademy/translate");
var _provider = _interopRequireWildcard(require("../atom/provider"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const renderWithContext = (component, options = {}) => {
  const {
    context = {},
    useLegacyProvider = false,
    ...renderOptions
  } = options;
  // uses mockTranslate as a default translate function
  const {
    translate = _translate.mockTranslate,
    ...rest
  } = context;
  const wrapper = ({
    children
  }) => {
    const hasContextTypes = useLegacyProvider || (0, _has.default)(['type', 'contextTypes'], children);
    // eslint-disable-next-line no-console
    if (!hasContextTypes) console.log('ContextTypes not found, using WebContext');
    return hasContextTypes ? /*#__PURE__*/_react.default.createElement(_provider.default, _extends({}, rest, {
      translate: translate
    }), children) : /*#__PURE__*/_react.default.createElement(_provider.WebContext, _extends({}, rest, {
      translate: translate
    }), children);
  };
  wrapper.propTypes = process.env.NODE_ENV !== "production" ? {
    children: _propTypes.default.node
  } : {};
  return (0, _react2.render)(component, {
    ...renderOptions,
    wrapper
  });
};
exports.renderWithContext = renderWithContext;
//# sourceMappingURL=render-with-context.js.map