'use strict';

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

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

var _validation2 = _interopRequireDefault(_validation);

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

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

var _constant = require('../../constant');

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

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

  try {
    var reg = new RegExp('^\\w+' + _constant.CONFIRM_SUFFIX + '$');
    if (reg.test(record.name)) {
      var vFunc = opt.formItemName;
      if (value && formValues[vFunc] !== value) {
        return new Error(opt.message || '与' + opt.description + '不一致');
      }
    } else {
      var confirmV = form.getFieldValue(record.name + _constant.CONFIRM_SUFFIX);
      !(0, _EmptyUtils.isEmpty)(confirmV) && form.validateFields([record.name + _constant.CONFIRM_SUFFIX], { force: true });
    }
  } catch (err) {
    return err;
  }
  return null;
};

exports.default = validator;