"use strict";

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

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

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

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 _classnames = _interopRequireDefault(require("classnames"));

var _EllipsisOutlined = _interopRequireDefault(require("@ant-design/icons/EllipsisOutlined"));

var _button = _interopRequireDefault(require("../button"));

var _configProvider = require("../config-provider");

var _dropdown = _interopRequireDefault(require("./dropdown"));

var __rest = void 0 && (void 0).__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};

var ButtonGroup = _button["default"].Group;

var DropdownButton = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(DropdownButton, _React$Component);

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

  function DropdownButton() {
    var _this;

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

    _this.renderButton = function (_ref) {
      var getContextPopupContainer = _ref.getPopupContainer,
          getPrefixCls = _ref.getPrefixCls;

      var _a = _this.props,
          customizePrefixCls = _a.prefixCls,
          type = _a.type,
          disabled = _a.disabled,
          onClick = _a.onClick,
          htmlType = _a.htmlType,
          children = _a.children,
          className = _a.className,
          overlay = _a.overlay,
          trigger = _a.trigger,
          align = _a.align,
          visible = _a.visible,
          onVisibleChange = _a.onVisibleChange,
          placement = _a.placement,
          getPopupContainer = _a.getPopupContainer,
          href = _a.href,
          _a$icon = _a.icon,
          icon = _a$icon === void 0 ? /*#__PURE__*/React.createElement(_EllipsisOutlined["default"], null) : _a$icon,
          title = _a.title,
          buttonsRender = _a.buttonsRender,
          restProps = __rest(_a, ["prefixCls", "type", "disabled", "onClick", "htmlType", "children", "className", "overlay", "trigger", "align", "visible", "onVisibleChange", "placement", "getPopupContainer", "href", "icon", "title", "buttonsRender"]);

      var prefixCls = getPrefixCls('dropdown-button', customizePrefixCls);
      var dropdownProps = {
        align: align,
        overlay: overlay,
        disabled: disabled,
        trigger: disabled ? [] : trigger,
        onVisibleChange: onVisibleChange,
        placement: placement,
        getPopupContainer: getPopupContainer || getContextPopupContainer
      };

      if ('visible' in _this.props) {
        dropdownProps.visible = visible;
      }

      var leftButton = /*#__PURE__*/React.createElement(_button["default"], {
        type: type,
        disabled: disabled,
        onClick: onClick,
        htmlType: htmlType,
        href: href,
        title: title
      }, children);
      var rightButton = /*#__PURE__*/React.createElement(_button["default"], {
        type: type,
        icon: icon
      });

      var _buttonsRender = buttonsRender([leftButton, rightButton]),
          _buttonsRender2 = (0, _slicedToArray2["default"])(_buttonsRender, 2),
          leftButtonToRender = _buttonsRender2[0],
          rightButtonToRender = _buttonsRender2[1];

      return /*#__PURE__*/React.createElement(ButtonGroup, (0, _extends2["default"])({}, restProps, {
        className: (0, _classnames["default"])(prefixCls, className)
      }), leftButtonToRender, /*#__PURE__*/React.createElement(_dropdown["default"], dropdownProps, rightButtonToRender));
    };

    return _this;
  }

  (0, _createClass2["default"])(DropdownButton, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement(_configProvider.ConfigConsumer, null, this.renderButton);
    }
  }]);
  return DropdownButton;
}(React.Component);

exports["default"] = DropdownButton;
DropdownButton.__ANT_BUTTON = true;
DropdownButton.defaultProps = {
  placement: 'bottomRight',
  type: 'default',
  buttonsRender: function buttonsRender(buttons) {
    return buttons;
  }
};