'use strict';

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

var _validation = require('../../../../utils/validation');

var _validation2 = _interopRequireDefault(_validation);

var _EmptyUtils = require('../../../../utils/EmptyUtils');

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

/**
 * Created by baoyinghai on 12/5/16.
 */
var validator = function validator(record) {
  var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  var formValues = arguments[2];
  var form = arguments[3];
  var opt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
  var isModalInputMappingItem = arguments[5];

  if (!(0, _EmptyUtils.isEmpty)(value) && typeof value !== 'string' || !isModalInputMappingItem && !(0, _EmptyUtils.isEmpty)(value) && value.length > (opt.length || record.length)) {
    return new Error(opt.message || '格式错误');
  }
  if (opt.minLength && opt.minLength > 0) {
    if (!(0, _EmptyUtils.isEmpty)(value) && value.length < opt.minLength) {
      return new Error('长度不能超过' + opt.minLength);
    }
  }
  return null;
};

exports.default = validator;