import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React, { Children, cloneElement, Component } from 'react';
import classNames from 'classnames';
import warning from '../_util/warning';
import RcDropdown from '../rc-components/dropdown';
import ConfigContext from '../config-provider/ConfigContext';

var Dropdown = /*#__PURE__*/function (_Component) {
  _inherits(Dropdown, _Component);

  var _super = _createSuper(Dropdown);

  function Dropdown() {
    var _this;

    _classCallCheck(this, Dropdown);

    _this = _super.apply(this, arguments);

    _this.renderOverlay = function () {
      var overlay = _this.props.overlay;
      var overlayElements = typeof overlay === 'function' ? overlay() : overlay;

      if (overlayElements) {
        var overlayElement = Children.only(overlayElements);
        var overlayProps = overlayElement.props;
        warning(!overlayProps.mode || overlayProps.mode === 'vertical', "mode=\"".concat(overlayProps.mode, "\" is not supported for Dropdown's Menu.")); // menu cannot be selectable in dropdown defaultly

        var _overlayProps$selecta = overlayProps.selectable,
            selectable = _overlayProps$selecta === void 0 ? false : _overlayProps$selecta,
            _overlayProps$focusab = overlayProps.focusable,
            focusable = _overlayProps$focusab === void 0 ? true : _overlayProps$focusab;
        return typeof overlayElement.type === 'string' ? overlayElement : /*#__PURE__*/cloneElement(overlayElement, {
          mode: 'vertical',
          selectable: selectable,
          focusable: focusable
        });
      }
    };

    return _this;
  }

  _createClass(Dropdown, [{
    key: "getTransitionName",
    value: function getTransitionName() {
      var _this$props = this.props,
          _this$props$placement = _this$props.placement,
          placement = _this$props$placement === void 0 ? '' : _this$props$placement,
          transitionName = _this$props.transitionName;

      if (transitionName !== undefined) {
        return transitionName;
      }

      if (placement.indexOf('top') >= 0) {
        return 'slide-down';
      }

      return 'slide-up';
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          children = _this$props2.children,
          customizePrefixCls = _this$props2.prefixCls,
          trigger = _this$props2.trigger,
          disabled = _this$props2.disabled;
      var getPrefixCls = this.context.getPrefixCls;
      var prefixCls = getPrefixCls('dropdown', customizePrefixCls);
      var child = Children.only(children);
      var dropdownTrigger = /*#__PURE__*/cloneElement(child, {
        className: classNames(child.props.className, "".concat(prefixCls, "-trigger")),
        disabled: disabled
      });
      var triggerActions = disabled ? [] : trigger;
      var alignPoint;

      if (triggerActions && triggerActions.indexOf('contextMenu') !== -1) {
        alignPoint = true;
      }

      return /*#__PURE__*/React.createElement(RcDropdown, _extends({
        alignPoint: alignPoint
      }, this.props, {
        prefixCls: prefixCls,
        transitionName: this.getTransitionName(),
        trigger: triggerActions,
        overlay: this.renderOverlay
      }), dropdownTrigger);
    }
  }], [{
    key: "contextType",
    get: function get() {
      return ConfigContext;
    }
  }]);

  return Dropdown;
}(Component);

export { Dropdown as default };
Dropdown.displayName = 'Dropdown';
Dropdown.defaultProps = {
  mouseEnterDelay: 0.15,
  mouseLeaveDelay: 0.1,
  placement: 'bottomLeft'
};
//# sourceMappingURL=dropdown.js.map
