"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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

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.default.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.default.Children.map(children, function (child) {
      return _react.default.cloneElement(child, {
        disabled: disabled,
        focus: focus,
        showSeparator: showSeparator
      });
    });

    return _react.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;
}(_react.default.Component);

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