'use strict';

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

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

var _validation2 = _interopRequireDefault(_validation);

var _JSExecutor = require('../../../../utils/JSExecutor');

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

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

var validator = function validator(record, value, formValues, form) {
  var opt = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};

  try {
    var vFunc = opt.validatorFunc;
    if (!(typeof vFunc === 'function')) {
      vFunc = (0, _JSExecutor.createFunc)(vFunc);
    }
    if (!(0, _EmptyUtils.isEmpty)(value) && !vFunc(formValues, value)) {
      return new Error(opt.message || '上下文检查错误');
    }
  } catch (err) {
    return err;
  }
  return null;
}; /**
    * Created by baoyinghai on 12/5/16.
    */
exports.default = validator;