'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = TabularCompoundInput;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _CustomCompoundInput = require('./CustomCompoundInput');

var _CustomCompoundInput2 = _interopRequireDefault(_CustomCompoundInput);

var _InputTableRow = require('./InputTableRow');

var _InputTableRow2 = _interopRequireDefault(_InputTableRow);

var _InputTableHeader = require('./InputTableHeader');

var _InputTableHeader2 = _interopRequireDefault(_InputTableHeader);

var _labelable = require('../enhancers/labelable');

var _labelable2 = _interopRequireDefault(_labelable);

var _repeatable = require('../enhancers/repeatable');

var _repeatable2 = _interopRequireDefault(_repeatable);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var BaseComponent = (0, _repeatable2.default)((0, _labelable2.default)(_CustomCompoundInput2.default));

var propTypes = _extends({}, BaseComponent.propTypes, {
  children: _react.PropTypes.node,
  repeating: _react.PropTypes.bool,
  renderChildInputLabel: _react.PropTypes.func
});

function TabularCompoundInput(props) {
  var children = props.children,
      repeating = props.repeating,
      renderChildInputLabel = props.renderChildInputLabel,
      remainingProps = _objectWithoutProperties(props, ['children', 'repeating', 'renderChildInputLabel']);

  var tableHeader = _react2.default.createElement(
    _InputTableHeader2.default,
    {
      embedded: repeating,
      renderLabel: renderChildInputLabel
    },
    children
  );

  return _react2.default.createElement(
    BaseComponent,
    _extends({}, remainingProps, {
      label: tableHeader,
      repeating: repeating
    }),
    _react2.default.createElement(
      _InputTableRow2.default,
      { embedded: repeating },
      children
    )
  );
}

TabularCompoundInput.propTypes = propTypes;