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

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 _rcCollapse = _interopRequireDefault(require("rc-collapse"));

var _classnames = _interopRequireDefault(require("classnames"));

var _AngleRight = _interopRequireDefault(require("../icon/AngleRight"));

var _CollapsePanel = _interopRequireDefault(require("./CollapsePanel"));

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

var _openAnimation = _interopRequireDefault(require("../_util/openAnimation"));

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

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

  function Collapse() {
    var _this;

    (0, _classCallCheck2["default"])(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(_AngleRight["default"], {
        rotate: panelProps.isActive ? 90 : undefined
      });
      return /*#__PURE__*/React.isValidElement(icon) ? /*#__PURE__*/React.cloneElement(icon, {
        className: (0, _classnames["default"])(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 = (0, _classnames["default"])((_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-borderless"), !bordered), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-icon-position-").concat(iconPosition), true), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _classNames), className);
      var openAnimation = (0, _extends2["default"])((0, _extends2["default"])({}, _openAnimation["default"]), {
        appear: function appear() {}
      });
      return /*#__PURE__*/React.createElement(_rcCollapse["default"], (0, _extends2["default"])({
        openAnimation: openAnimation
      }, _this.props, {
        expandIcon: function expandIcon(panelProps) {
          return _this.renderExpandIcon(panelProps, prefixCls);
        },
        prefixCls: prefixCls,
        className: collapseClassName
      }));
    };

    return _this;
  }

  (0, _createClass2["default"])(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(_configProvider.ConfigConsumer, null, this.renderCollapse);
    }
  }]);
  return Collapse;
}(React.Component);

exports["default"] = Collapse;
Collapse.Panel = _CollapsePanel["default"];
Collapse.defaultProps = {
  bordered: true
};