import _extends from "@babel/runtime/helpers/extends";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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";

var __rest = this && this.__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;
};

import * as React from 'react';
import classNames from 'classnames';
import EllipsisOutlined from '@ant-design/icons/EllipsisOutlined';
import Button from '../button';
import { ConfigConsumer } from '../config-provider';
import Dropdown from './dropdown';
var ButtonGroup = Button.Group;

var DropdownButton = /*#__PURE__*/function (_React$Component) {
  _inherits(DropdownButton, _React$Component);

  var _super = _createSuper(DropdownButton);

  function DropdownButton() {
    var _this;

    _classCallCheck(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, 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, {
        type: type,
        disabled: disabled,
        onClick: onClick,
        htmlType: htmlType,
        href: href,
        title: title
      }, children);
      var rightButton = /*#__PURE__*/React.createElement(Button, {
        type: type,
        icon: icon
      });

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

      return /*#__PURE__*/React.createElement(ButtonGroup, _extends({}, restProps, {
        className: classNames(prefixCls, className)
      }), leftButtonToRender, /*#__PURE__*/React.createElement(Dropdown, dropdownProps, rightButtonToRender));
    };

    return _this;
  }

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

  return DropdownButton;
}(React.Component);

export { DropdownButton as default };
DropdownButton.__ANT_BUTTON = true;
DropdownButton.defaultProps = {
  placement: 'bottomRight',
  type: 'default',
  buttonsRender: function buttonsRender(buttons) {
    return buttons;
  }
};