"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;exports.__esModule = true;exports.isInstanceWithRootNode = void 0;exports.rootNode = rootNode;var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _eventemitter = _interopRequireDefault(require("eventemitter3"));



var _getRootNode = require("./getRootNode");

























function rootNode(Component) {var _Class;
  var rootNode = (_Class = /*#__PURE__*/function (_Component) {





    function rootNode() {var _this;
      _this = _Component.call(this, arguments.length <= 0 ? undefined : arguments[0]) || this;_this.rootNode = Component.defaultRootNode;_this.rootNodeEmitter = new _eventemitter.default();_this.


      setRootNode = function (instance) {
        var _rootNode = (0, _getRootNode.getRootNode)(instance);
        if (_rootNode !== _this.rootNode) {
          _this.rootNode = _rootNode;
          _this.rootNodeEmitter.emit('change', _rootNode);
        }
      };_this.

      getRootNode = function () {
        return _this.rootNode;
      };_this.

      addRootNodeChangeListener = function (callback) {
        _this.rootNodeEmitter.addListener('change', callback);
        return {
          remove: function remove() {
            _this.rootNodeEmitter.removeListener('change', callback);
          }
        };
      };return _this;}(0, _inheritsLoose2.default)(rootNode, _Component);return rootNode;}(Component), _Class.__KONTUR_REACT_UI__ = Component.__KONTUR_REACT_UI__, _Class.displayName = Component.displayName, _Class);


  var nameDescriptor = Object.getOwnPropertyDescriptor(rootNode, 'name');
  if (!nameDescriptor || nameDescriptor.configurable) {
    Object.defineProperty(rootNode, 'name', { value: Component.name });
  }

  return rootNode;
}

var isInstanceWithRootNode = exports.isInstanceWithRootNode = function isInstanceWithRootNode(instance) {
  return Boolean(instance) && Object.prototype.hasOwnProperty.call(instance, 'getRootNode');
};