'use strict';

exports.__esModule = true;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * @category layout
 * @component accordion
 * @variations collab-ui-react
 */

var AccordionGroup = function (_React$Component) {
  (0, _inherits3.default)(AccordionGroup, _React$Component);

  function AccordionGroup() {
    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, AccordionGroup);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.getChildContext = function () {
      return {
        onClick: _this.props.onClick,
        onKeyDown: _this.props.onKeyDown
      };
    }, _this.verifyChildren = function () {
      var children = _this.props.children;

      var childrenArr = _react2.default.Children.toArray(children);
      return children && childrenArr.length === 2 && childrenArr[0].type.displayName === 'AccordionHeader' && childrenArr[1].type.displayName === 'AccordionContent';
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  AccordionGroup.prototype.componentWillMount = function componentWillMount() {
    if (!this.verifyChildren()) {
      throw new Error('AccordionGroup should contain 2 children ' + 'AccordionHeader and AccordionContent respectively.');
    }
  };

  AccordionGroup.prototype.render = function render() {
    var _props = this.props,
        children = _props.children,
        className = _props.className,
        isExpanded = _props.isExpanded,
        disabled = _props.disabled,
        focus = _props.focus,
        showSeparator = _props.showSeparator;


    var setGroupContent = _react2.default.Children.map(children, function (child) {
      return _react2.default.cloneElement(child, {
        disabled: disabled,
        focus: focus,
        showSeparator: showSeparator
      });
    });

    return _react2.default.createElement(
      'div',
      {
        'aria-expanded': isExpanded,
        className: 'cui-accordion__group' + ('' + (disabled && ' cui-accordion__group--disabled' || '')) + ('' + (isExpanded && ' cui-accordion__group--active' || '')) + ('' + (className && ' ' + className || ''))
      },
      setGroupContent
    );
  };

  return AccordionGroup;
}(_react2.default.Component);

AccordionGroup.displayName = 'AccordionGroup';
AccordionGroup.childContextTypes = {
  onClick: _propTypes2.default.func,
  onKeyDown: _propTypes2.default.func
};
exports.default = AccordionGroup;


AccordionGroup.defaultProps = {
  children: null,
  isExpanded: false,
  onClick: null,
  onKeyDown: null,
  className: '',
  disabled: false,
  focus: false,
  showSeparator: false
};
module.exports = exports['default'];