import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 * as React from 'react';
import RcCollapse from 'rc-collapse';
import classNames from 'classnames';
import RightOutlined from '../icon/AngleRight';
import CollapsePanel from './CollapsePanel';
import { ConfigConsumer } from '../config-provider';
import animation from '../_util/openAnimation';

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

  var _super = _createSuper(Collapse);

  function Collapse() {
    var _this;

    _classCallCheck(this, Collapse);

    _this = _super.apply(this, arguments);

    _this.renderExpandIcon = function () {
      var panelProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var prefixCls = arguments.length > 1 ? arguments[1] : undefined;
      var expandIcon = _this.props.expandIcon;
      var icon = expandIcon ? expandIcon(panelProps) : /*#__PURE__*/React.createElement(RightOutlined, {
        rotate: panelProps.isActive ? 90 : undefined
      });
      return /*#__PURE__*/React.isValidElement(icon) ? /*#__PURE__*/React.cloneElement(icon, {
        className: classNames(icon.props.className, "".concat(prefixCls, "-arrow"))
      }) : icon;
    };

    _this.renderCollapse = function (_ref) {
      var _classNames;

      var getPrefixCls = _ref.getPrefixCls,
          direction = _ref.direction;
      var _this$props = _this.props,
          customizePrefixCls = _this$props.prefixCls,
          _this$props$className = _this$props.className,
          className = _this$props$className === void 0 ? '' : _this$props$className,
          bordered = _this$props.bordered;
      var prefixCls = getPrefixCls('collapse', customizePrefixCls);

      var iconPosition = _this.getIconPosition(direction);

      var collapseClassName = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-borderless"), !bordered), _defineProperty(_classNames, "".concat(prefixCls, "-icon-position-").concat(iconPosition), true), _defineProperty(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _classNames), className);

      var openAnimation = _extends(_extends({}, animation), {
        appear: function appear() {}
      });

      return /*#__PURE__*/React.createElement(RcCollapse, _extends({
        openAnimation: openAnimation
      }, _this.props, {
        expandIcon: function expandIcon(panelProps) {
          return _this.renderExpandIcon(panelProps, prefixCls);
        },
        prefixCls: prefixCls,
        className: collapseClassName
      }));
    };

    return _this;
  }

  _createClass(Collapse, [{
    key: "getIconPosition",
    value: function getIconPosition() {
      var direction = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'ltr';
      var expandIconPosition = this.props.expandIconPosition;

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

      return direction === 'rtl' ? 'right' : 'left';
    }
  }, {
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement(ConfigConsumer, null, this.renderCollapse);
    }
  }]);

  return Collapse;
}(React.Component);

export { Collapse as default };
Collapse.Panel = CollapsePanel;
Collapse.defaultProps = {
  bordered: true
};