text: 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; };
  
  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; }; }();
  
  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; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  import { Component, createElement } from 'react';
  import PropTypes from 'prop-types';
  import invariant from 'invariant';
  import createConnectedFieldArray from './ConnectedFieldArray';
  import prefixName from './util/prefixName';
  
  var toArray = function toArray(value) {
    return Array.isArray(value) ? value : [value];
  };
  
  var wrapError = function wrapError(fn, key) {
    return fn && function () {
      var validators = toArray(fn);
      for (var i = 0; i < validators.length; i++) {
        var result = validators[i].apply(validators, arguments);
        if (result) {
          return _defineProperty({}, key, result);
        }
      }
    };
  };
  
  var createFieldArray = function createFieldArray(_ref2) {
    var deepEqual = _ref2.deepEqual,
        getIn = _ref2.getIn,
        size = _ref2.size;
  
  
    var ConnectedFieldArray = createConnectedFieldArray({ deepEqual: deepEqual, getIn: getIn, size: size });
  
    var FieldArray = function (_Component) {
      _inherits(FieldArray, _Component);
  
      function FieldArray(props, context) {
        _classCallCheck(this, FieldArray);
  
        var _this = _possibleConstructorReturn(this, (FieldArray.__proto__ || Object.getPrototypeOf(FieldArray)).call(this, props, context));
  
        if (!context._reduxForm) {
          throw new Error('FieldArray must be inside a component decorated with reduxForm()');
        }
        return _this;
      }
  
      _createClass(FieldArray, [{
        key: 'componentWillMount',
        value: function componentWillMount() {
          var _this2 = this;
  
          this.context._reduxForm.register(this.name, 'FieldArray', function () {
            return wrapError(_this2.props.validate, '_error');
          }, function () {
            return wrapError(_this2.props.warn, '_warning');
          });
        }
      }, {
        key: 'componentWillReceiveProps',
        value: function componentWillReceiveProps(nextProps) {
          if (this.props.name !== nextProps.name) {
            // unregister old name
            this.context._reduxForm.unregister(this.name);
            // register new name
            this.context._reduxForm.register(prefixName(this.context, nextProps.name), 'FieldArray');
          }
        }
      }, {
        key: 'componentWillUnmount',
        value: function componentWillUnmount() {
          this.context._reduxForm.unregister(this.name);
        }
      }, {
        key: 'getRenderedComponent',
        value: function getRenderedComponent() {
          invariant(this.props.withRef, 'If you want to access getRenderedComponent(), ' + 'you must specify a withRef prop to FieldArray');
          return this.refs.connected.getWrappedInstance().getRenderedComponent();
        }
      }, {
        key: 'render',
        value: function render() {
          return createElement(ConnectedFieldArray, _extends({}, this.props, {
            name: this.name,
            syncError: this.syncError,
            syncWarning: this.syncWarning,
            _reduxForm: this.context._reduxForm,
            ref: 'connected'
          }));
        }
      }, {
        key: 'name',
        get: function get() {
          return prefixName(this.context, this.props.name);
        }
      }, {
        key: 'dirty',
        get: function get() {
          return this.refs.connected.getWrappedInstance().dirty;
        }
      }, {
        key: 'pristine',
        get: function get() {
          return this.refs.connected.getWrappedInstance().pristine;
        }
      }, {
        key: 'value',
        get: function get() {
          return this.refs.connected.getWrappedInstance().value;
        }
      }]);
  
      return FieldArray;
    }(Component);
  
    FieldArray.propTypes = {
      name: PropTypes.string.isRequired,
      component: PropTypes.func.isRequired,
      props: PropTypes.object,
      validate: PropTypes.oneOfType([PropTypes.func, PropTypes.arrayOf(PropTypes.func)]),
      warn: PropTypes.oneOfType([PropTypes.func, PropTypes.arrayOf(PropTypes.func)]),
      withRef: PropTypes.bool
    };
    FieldArray.contextTypes = {
      _reduxForm: PropTypes.object
    };
  
    return FieldArray;
  };
  
  export default createFieldArray;