text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _propTypes = require('prop-types');
  
  var _propTypes2 = _interopRequireDefault(_propTypes);
  
  var _Panel = require('./Panel');
  
  var _Panel2 = _interopRequireDefault(_Panel);
  
  var _openAnimationFactory = require('./openAnimationFactory');
  
  var _openAnimationFactory2 = _interopRequireDefault(_openAnimationFactory);
  
  var _classnames = require('classnames');
  
  var _classnames2 = _interopRequireDefault(_classnames);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
  
  function toArray(activeKey) {
    var currentActiveKey = activeKey;
    if (!Array.isArray(currentActiveKey)) {
      currentActiveKey = currentActiveKey ? [currentActiveKey] : [];
    }
    return currentActiveKey;
  }
  
  var Collapse = function (_Component) {
    _inherits(Collapse, _Component);
  
    function Collapse(props) {
      _classCallCheck(this, Collapse);
  
      var _this = _possibleConstructorReturn(this, _Component.call(this, props));
  
      var _this$props = _this.props,
          activeKey = _this$props.activeKey,
          defaultActiveKey = _this$props.defaultActiveKey;
  
      var currentActiveKey = defaultActiveKey;
      if ('activeKey' in _this.props) {
        currentActiveKey = activeKey;
      }
  
      _this.state = {
        openAnimation: _this.props.openAnimation || (0, _openAnimationFactory2["default"])(_this.props.prefixCls),
        activeKey: toArray(currentActiveKey)
      };
      return _this;
    }
  
    Collapse.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
      if ('activeKey' in nextProps) {
        this.setState({
          activeKey: toArray(nextProps.activeKey)
        });
      }
      if ('openAnimation' in nextProps) {
        this.setState({
          openAnimation: nextProps.openAnimation
        });
      }
    };
  
    Collapse.prototype.onClickItem = function onClickItem(key) {
      var _this2 = this;
  
      return function () {
        var activeKey = _this2.state.activeKey;
        if (_this2.props.accordion) {
          activeKey = activeKey[0] === key ? [] : [key];
        } else {
          activeKey = [].concat(_toConsumableArray(activeKey));
          var index = activeKey.indexOf(key);
          var isActive = index > -1;
          if (isActive) {
            // remove active state
            activeKey.splice(index, 1);
          } else {
            activeKey.push(key);
          }
        }
        _this2.setActiveKey(activeKey);
      };
    };
  
    Collapse.prototype.getItems = function getItems() {
      var _this3 = this;
  
      var activeKey = this.state.activeKey;
      var _props = this.props,
          prefixCls = _props.prefixCls,
          accordion = _props.accordion,
          destroyInactivePanel = _props.destroyInactivePanel;
  
      var newChildren = [];
  
      _react.Children.forEach(this.props.children, function (child, index) {
        if (!child) return;
        // If there is no key provide, use the panel order as default key
        var key = child.key || String(index);
        var header = child.props.header;
        var headerClass = child.props.headerClass;
        var isActive = false;
        if (accordion) {
          isActive = activeKey[0] === key;
        } else {
          isActive = activeKey.indexOf(key) > -1;
        }
  
        var props = {
          key: key,
          header: header,
          headerClass: headerClass,
          isActive: isActive,
          prefixCls: prefixCls,
          destroyInactivePanel: destroyInactivePanel,
          openAnimation: _this3.state.openAnimation,
          children: child.props.children,
          onItemClick: _this3.onClickItem(key).bind(_this3)
        };
  
        newChildren.push(_react2["default"].cloneElement(child, props));
      });
  
      return newChildren;
    };
  
    Collapse.prototype.setActiveKey = function setActiveKey(activeKey) {
      if (!('activeKey' in this.props)) {
        this.setState({ activeKey: activeKey });
      }
      this.props.onChange(this.props.accordion ? activeKey[0] : activeKey);
    };
  
    Collapse.prototype.render = function render() {
      var _classNames;
  
      var _props2 = this.props,
          prefixCls = _props2.prefixCls,
          className = _props2.className,
          style = _props2.style;
  
      var collapseClassName = (0, _classnames2["default"])((_classNames = {}, _defineProperty(_classNames, prefixCls, true), _defineProperty(_classNames, className, !!className), _classNames));
      return _react2["default"].createElement(
        'div',
        { className: collapseClassName, style: style },
        this.getItems()
      );
    };
  
    return Collapse;
  }(_react.Component);
  
  Collapse.propTypes = {
    children: _propTypes2["default"].any,
    prefixCls: _propTypes2["default"].string,
    activeKey: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].arrayOf(_propTypes2["default"].string)]),
    defaultActiveKey: _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].arrayOf(_propTypes2["default"].string)]),
    openAnimation: _propTypes2["default"].object,
    onChange: _propTypes2["default"].func,
    accordion: _propTypes2["default"].bool,
    className: _propTypes2["default"].string,
    style: _propTypes2["default"].object,
    destroyInactivePanel: _propTypes2["default"].bool
  };
  
  Collapse.defaultProps = {
    prefixCls: 'rc-collapse',
    onChange: function onChange() {},
  
    accordion: false,
    destroyInactivePanel: false
  };
  
  Collapse.Panel = _Panel2["default"];
  
  exports["default"] = Collapse;
  module.exports = exports['default'];