"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

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 _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = require("react");

var TriggerChild = /*#__PURE__*/function (_PureComponent) {
  (0, _inherits2["default"])(TriggerChild, _PureComponent);

  var _super = (0, _createSuper2["default"])(TriggerChild);

  function TriggerChild(props, context) {
    var _this;

    (0, _classCallCheck2["default"])(this, TriggerChild);
    _this = _super.call(this, props, context);

    var createChains = function createChains(eventName) {
      return function (e) {
        var _this$props = _this.props,
            handle = _this$props["on".concat(eventName)],
            children = _this$props.children;

        var child = _react.Children.only(children);

        if (handle) {
          return handle(eventName, child, e);
        }

        if (child) {
          var childHandle = child.props["on".concat(eventName)];

          if (childHandle) {
            return childHandle(e);
          }
        }
      };
    };

    _this.handleContextMenu = createChains('ContextMenu');
    _this.handleClick = createChains('Click');
    _this.handleMouseDown = createChains('MouseDown');
    _this.handleMouseEnter = createChains('MouseEnter');
    _this.handleMouseLeave = createChains('MouseLeave');
    _this.handleFocus = createChains('Focus');
    _this.handleBlur = createChains('Blur');
    _this.handleKeyDown = createChains('KeyDown');
    return _this;
  }

  (0, _createClass2["default"])(TriggerChild, [{
    key: "render",
    value: function render() {
      var children = this.props.children;
      return /*#__PURE__*/(0, _react.cloneElement)(_react.Children.only(children), {
        onContextMenu: this.handleContextMenu,
        onClick: this.handleClick,
        onMouseDown: this.handleMouseDown,
        onMouseEnter: this.handleMouseEnter,
        onMouseLeave: this.handleMouseLeave,
        onFocus: this.handleFocus,
        onBlur: this.handleBlur,
        onKeyDown: this.handleKeyDown
      });
    }
  }]);
  return TriggerChild;
}(_react.PureComponent);

exports["default"] = TriggerChild;
TriggerChild.displayName = 'TriggerChild';
//# sourceMappingURL=TriggerChild.js.map
