'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _OptClass = require('../internal/OptClass');

var _OptClass2 = _interopRequireDefault(_OptClass);

var _style = require('./style.scss');

var _style2 = _interopRequireDefault(_style);

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

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) : subClass.__proto__ = superClass; }

var Panel = function (_React$Component) {
  _inherits(Panel, _React$Component);

  function Panel(props) {
    _classCallCheck(this, Panel);

    var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Panel).call(this, props));

    _this.getHeader = function () {
      return _this.props.children[0];
    };

    _this.handlePanelClick = function () {
      if (_this.props.onPanelClick) {
        _this.props.onPanelClick(_this);
      }
    };

    return _this;
  }

  _createClass(Panel, [{
    key: 'render',
    value: function render() {
      var panelActiveClass = this.props.active ? _style2.default['panel-active'] : null;
      var panelClasses = (0, _OptClass2.default)(_style2.default, ['panel', panelActiveClass], this.props.optClass);

      var header = _react2.default.cloneElement(this.getHeader(), {
        active: this.props.active,
        onPanelClick: this.handlePanelClick
      });

      return _react2.default.createElement(
        'div',
        { className: panelClasses },
        header,
        this.props.children[1]
      );
    }
  }]);

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

Panel.propTypes = {
  /**
   * Whether the panel is active. Set by the panelGroup component.
   */
  active: _react2.default.PropTypes.bool,
  /**
   * Optional CSS class(es) to be used for local styles (string or array of strings)
   */
  optClass: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.array, _react2.default.PropTypes.string])
};
exports.default = Panel;