function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

/**
 * @category layout
 * @component accordion
 * @variations collab-ui-react
 */
import React from 'react';
import PropTypes from 'prop-types';

var AccordionGroup =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(AccordionGroup, _React$Component);

  function AccordionGroup() {
    var _this;

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

    _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 = React.Children.toArray(children);
      return children && childrenArr.length === 2 && childrenArr[0].type.displayName === 'AccordionHeader' && childrenArr[1].type.displayName === 'AccordionContent';
    };

    return _this;
  }

  var _proto = AccordionGroup.prototype;

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

  _proto.render = function render() {
    var _this$props = this.props,
        children = _this$props.children,
        className = _this$props.className,
        isExpanded = _this$props.isExpanded,
        disabled = _this$props.disabled,
        focus = _this$props.focus,
        showSeparator = _this$props.showSeparator;
    var setGroupContent = React.Children.map(children, function (child) {
      return React.cloneElement(child, {
        disabled: disabled,
        focus: focus,
        showSeparator: showSeparator
      });
    });
    return React.createElement("div", {
      "aria-expanded": isExpanded,
      className: "cui-accordion__group" + ("" + (disabled && ' cui-accordion__group--disabled' || '')) + ("" + (isExpanded && " cui-accordion__group--active" || '')) + ("" + (className && " " + className || ''))
    }, setGroupContent);
  };

  return AccordionGroup;
}(React.Component);

AccordionGroup.displayName = 'AccordionGroup';
AccordionGroup.childContextTypes = {
  onClick: PropTypes.func,
  onKeyDown: PropTypes.func
};
AccordionGroup.propTypes = {
  children: PropTypes.node,
  isExpanded: PropTypes.bool,
  disabled: PropTypes.bool,
  onClick: PropTypes.func,
  onKeyDown: PropTypes.func,
  className: PropTypes.string,
  focus: PropTypes.bool,
  showSeparator: PropTypes.bool
};
AccordionGroup.defaultProps = {
  children: null,
  isExpanded: false,
  onClick: null,
  onKeyDown: null,
  className: '',
  disabled: false,
  focus: false,
  showSeparator: false
};
export default AccordionGroup;