text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _extends2 = require('babel-runtime/helpers/extends');
  
  var _extends3 = _interopRequireDefault(_extends2);
  
  var _typeof2 = require('babel-runtime/helpers/typeof');
  
  var _typeof3 = _interopRequireDefault(_typeof2);
  
  exports.argumentContainer = argumentContainer;
  exports.identity = identity;
  exports.flattenArray = flattenArray;
  exports.treeTraverse = treeTraverse;
  exports.flattenFields = flattenFields;
  exports.normalizeValidateRules = normalizeValidateRules;
  exports.getValidateTriggers = getValidateTriggers;
  exports.getValueFromEvent = getValueFromEvent;
  exports.getErrorStrs = getErrorStrs;
  exports.getParams = getParams;
  exports.isEmptyObject = isEmptyObject;
  exports.hasRules = hasRules;
  exports.startsWith = startsWith;
  
  var _hoistNonReactStatics = require('hoist-non-react-statics');
  
  var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  
  function getDisplayName(WrappedComponent) {
    return WrappedComponent.displayName || WrappedComponent.name || 'WrappedComponent';
  }
  
  function argumentContainer(Container, WrappedComponent) {
    /* eslint no-param-reassign:0 */
    Container.displayName = 'Form(' + getDisplayName(WrappedComponent) + ')';
    Container.WrappedComponent = WrappedComponent;
    return (0, _hoistNonReactStatics2['default'])(Container, WrappedComponent);
  }
  
  function identity(obj) {
    return obj;
  }
  
  function flattenArray(arr) {
    return Array.prototype.concat.apply([], arr);
  }
  
  function treeTraverse() {
    var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
    var tree = arguments[1];
    var isLeafNode = arguments[2];
    var errorMessage = arguments[3];
    var callback = arguments[4];
  
    if (isLeafNode(path, tree)) {
      callback(path, tree);
    } else if (tree === undefined) {
      return;
    } else if (Array.isArray(tree)) {
      tree.forEach(function (subTree, index) {
        return treeTraverse(path + '[' + index + ']', subTree, isLeafNode, errorMessage, callback);
      });
    } else {
      // It's object and not a leaf node
      if ((typeof tree === 'undefined' ? 'undefined' : (0, _typeof3['default'])(tree)) !== 'object') {
        console.error(errorMessage);
        return;
      }
      Object.keys(tree).forEach(function (subTreeKey) {
        var subTree = tree[subTreeKey];
        treeTraverse('' + path + (path ? '.' : '') + subTreeKey, subTree, isLeafNode, errorMessage, callback);
      });
    }
  }
  
  function flattenFields(maybeNestedFields, isLeafNode, errorMessage) {
    var fields = {};
    treeTraverse(undefined, maybeNestedFields, isLeafNode, errorMessage, function (path, node) {
      fields[path] = node;
    });
    return fields;
  }
  
  function normalizeValidateRules(validate, rules, validateTrigger) {
    var validateRules = validate.map(function (item) {
      var newItem = (0, _extends3['default'])({}, item, {
        trigger: item.trigger || []
      });
      if (typeof newItem.trigger === 'string') {
        newItem.trigger = [newItem.trigger];
      }
      return newItem;
    });
    if (rules) {
      validateRules.push({
        trigger: validateTrigger ? [].concat(validateTrigger) : [],
        rules: rules
      });
    }
    return validateRules;
  }
  
  function getValidateTriggers(validateRules) {
    return validateRules.filter(function (item) {
      return !!item.rules && item.rules.length;
    }).map(function (item) {
      return item.trigger;
    }).reduce(function (pre, curr) {
      return pre.concat(curr);
    }, []);
  }
  
  function getValueFromEvent(e) {
    // To support custom element
    if (!e || !e.target) {
      return e;
    }
    var target = e.target;
  
    return target.type === 'checkbox' ? target.checked : target.value;
  }
  
  function getErrorStrs(errors) {
    if (errors) {
      return errors.map(function (e) {
        if (e && e.message) {
          return e.message;
        }
        return e;
      });
    }
    return errors;
  }
  
  function getParams(ns, opt, cb) {
    var names = ns;
    var options = opt;
    var callback = cb;
    if (cb === undefined) {
      if (typeof names === 'function') {
        callback = names;
        options = {};
        names = undefined;
      } else if (Array.isArray(names)) {
        if (typeof options === 'function') {
          callback = options;
          options = {};
        } else {
          options = options || {};
        }
      } else {
        callback = options;
        options = names || {};
        names = undefined;
      }
    }
    return {
      names: names,
      options: options,
      callback: callback
    };
  }
  
  function isEmptyObject(obj) {
    return Object.keys(obj).length === 0;
  }
  
  function hasRules(validate) {
    if (validate) {
      return validate.some(function (item) {
        return item.rules && item.rules.length;
      });
    }
    return false;
  }
  
  function startsWith(str, prefix) {
    return str.lastIndexOf(prefix, 0) === 0;
  }