'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _inputHelpers = require('../helpers/inputHelpers');

var _normalizeLabel = require('../helpers/normalizeLabel');

var _normalizeLabel2 = _interopRequireDefault(_normalizeLabel);

var _InputTableHeader = require('../../styles/cspace-input/InputTableHeader.css');

var _InputTableHeader2 = _interopRequireDefault(_InputTableHeader);

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

var propTypes = {
  children: _react.PropTypes.node,
  embedded: _react.PropTypes.bool,
  renderLabel: _react.PropTypes.func
};

var defaultProps = {
  renderLabel: function renderLabel(input) {
    return (0, _normalizeLabel2.default)(input.props.label);
  }
};

function InputTableHeader(props) {
  var children = props.children,
      embedded = props.embedded,
      renderLabel = props.renderLabel;


  var inputs = (0, _inputHelpers.extractInputs)(children);
  var labels = inputs.map(function (input) {
    return renderLabel(input);
  });

  if (!labels.some(function (label) {
    return !!label;
  })) {
    return null;
  }

  var labelContainers = labels.map(function (label, index) {
    return _react2.default.createElement(
      'div',
      { key: inputs[index].props.name || index },
      label
    );
  });

  var className = embedded ? _InputTableHeader2.default.embedded : _InputTableHeader2.default.normal;

  return _react2.default.createElement(
    'div',
    { className: className },
    labelContainers
  );
}

InputTableHeader.propTypes = propTypes;
InputTableHeader.defaultProps = defaultProps;