"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

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

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

var _react = _interopRequireWildcard(require("react"));

var _animate = _interopRequireDefault(require("../animate"));

var _createChains = _interopRequireDefault(require("../_util/createChains"));

var _MouseDown = _interopRequireDefault(require("./MouseDown"));

var _excluded = ["prefixCls"];

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

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

  function RippleChild() {
    var _this;

    (0, _classCallCheck2["default"])(this, RippleChild);
    _this = _super.apply(this, arguments);

    _this.handleMouseDown = function (child, size) {
      var _this$props = _this.props,
          prefixCls = _this$props.prefixCls,
          rest = (0, _objectWithoutProperties2["default"])(_this$props, _excluded);
      var _child$props = child.props,
          children = _child$props.children,
          style = _child$props.style;

      if (size) {
        var x = size.x,
            y = size.y,
            width = size.width,
            height = size.height;
        var maxWidth = Math.max(width - x, x);
        var maxHeight = Math.max(height - y, y);
        var max = Math.sqrt(maxWidth * maxWidth + maxHeight * maxHeight);
        _this.currentCircleStyle = {
          width: max + max,
          height: max + max,
          left: x - max,
          top: y - max
        };
      }

      var newProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, (0, _createChains["default"])(rest, child.props)), {}, {
        children: [children, /*#__PURE__*/_react["default"].createElement(_animate["default"], {
          key: "ripple",
          component: "div",
          componentProps: _this.getComponentProps(prefixCls),
          transitionName: size ? 'zoom-small-slow' : 'fade',
          hiddenProp: "hidden"
        }, _this.currentCircleStyle && /*#__PURE__*/_react["default"].createElement("div", {
          hidden: !size,
          className: prefixCls,
          key: "circle",
          style: _this.currentCircleStyle
        }))],
        style: _this.currentStyle || style
      });

      if (size && size.position === 'static') {
        newProps.style = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
          position: 'relative'
        });
        _this.currentStyle = newProps.style;
      }

      return /*#__PURE__*/(0, _react.cloneElement)(child, newProps);
    };

    _this.ripple = function (child) {
      if ( /*#__PURE__*/(0, _react.isValidElement)(child)) {
        return /*#__PURE__*/_react["default"].createElement(_MouseDown["default"], {
          rippleChild: child
        }, _this.handleMouseDown);
      }

      return child;
    };

    return _this;
  }

  (0, _createClass2["default"])(RippleChild, [{
    key: "render",
    value: function render() {
      var children = this.props.children;
      return this.ripple(_react.Children.only(children));
    }
  }, {
    key: "getComponentProps",
    value: function getComponentProps(prefixCls) {
      var className = "".concat(prefixCls, "-wrapper");
      var componentProps = this.componentProps;

      if (!componentProps || className !== componentProps.className) {
        this.componentProps = {
          className: className
        };
      }

      return this.componentProps;
    }
  }]);
  return RippleChild;
}(_react.PureComponent);

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