"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = withActivityProvider;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireDefault(require("react"));
var _providerFactory2 = require("../../provider-factory");
var _excluded = ["providerFactory"];
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
// eslint-disable-next-line no-duplicate-imports

function withActivityProvider(WrappedComponent) {
  return /*#__PURE__*/function (_React$Component) {
    function WithActivityProvider() {
      var _this;
      (0, _classCallCheck2.default)(this, WithActivityProvider);
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
      _this = _callSuper(this, WithActivityProvider, [].concat(args));
      (0, _defineProperty2.default)(_this, "renderNode", function (providers) {
        var _ref = _this.props,
          _providerFactory = _ref.providerFactory,
          props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
        var activityProvider = providers.activityProvider;

        // Ignored via go/ees005
        // eslint-disable-next-line @typescript-eslint/no-explicit-any, react/jsx-props-no-spreading
        return /*#__PURE__*/_react.default.createElement(WrappedComponent, (0, _extends2.default)({
          activityProvider: activityProvider
        }, props));
      });
      return _this;
    }
    (0, _inherits2.default)(WithActivityProvider, _React$Component);
    return (0, _createClass2.default)(WithActivityProvider, [{
      key: "render",
      value: function render() {
        var providerFactory = this.props.providerFactory;
        return /*#__PURE__*/_react.default.createElement(_providerFactory2.WithProviders
        // Memoising this array causes the component fail tests in platform/packages/editor/editor-plugin-media-tests/src/__tests__/playwright/media-link.spec.ts because the WithProviders component doesn't update when the parent rerenders - this is a bug with the underlying WithProviders component
        // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
        , {
          providers: ['activityProvider'],
          providerFactory: providerFactory,
          renderNode: this.renderNode
        });
      }
    }]);
  }(_react.default.Component);
}