"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 _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 = _interopRequireWildcard(require("react"));
var _providerFactory = require("../../provider-factory");
var _mentionWithProviders = require("./mention-with-providers");
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); }
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 @repo/internal/react/no-class-components */
var Mention = exports.default = /*#__PURE__*/function (_PureComponent) {
  function Mention(props) {
    var _this;
    (0, _classCallCheck2.default)(this, Mention);
    _this = _callSuper(this, Mention, [props]);
    (0, _defineProperty2.default)(_this, "renderWithProvider", function (providers) {
      var _this$props = _this.props,
        accessLevel = _this$props.accessLevel,
        eventHandlers = _this$props.eventHandlers,
        id = _this$props.id,
        text = _this$props.text,
        localId = _this$props.localId;
      var mentionProvider = providers.mentionProvider,
        profilecardProvider = providers.profilecardProvider;
      return /*#__PURE__*/_react.default.createElement(_mentionWithProviders.MentionWithProviders, {
        id: id,
        text: text,
        accessLevel: accessLevel,
        localId: localId,
        eventHandlers: eventHandlers,
        mentionProvider: mentionProvider,
        profilecardProvider: profilecardProvider
      });
    });
    _this.providerFactory = props.providers || new _providerFactory.ProviderFactory();
    return _this;
  }
  (0, _inherits2.default)(Mention, _PureComponent);
  return (0, _createClass2.default)(Mention, [{
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      if (!this.props.providers) {
        // new ProviderFactory is created if no `providers` has been set
        // in this case when component is unmounted it's safe to destroy this providerFactory
        this.providerFactory.destroy();
      }
    }
  }, {
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react.default.createElement(_providerFactory.WithProviders
      // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
      , {
        providers: ['mentionProvider', 'profilecardProvider'],
        providerFactory: this.providerFactory,
        renderNode: this.renderWithProvider
      });
    }
  }]);
}(_react.PureComponent);