/**
 * Created by baoyinghai on 12/5/16.
 */
import validation from '../../../../utils/validation';
import { createFunc } from '../../../../utils/JSExecutor';
import { isEmpty } from '../../../../utils/EmptyUtils';

const validator = (record, value, formValues, form, opt = {}) => {
  try {
    let vFunc = opt.validatorFunc;
    if (!(typeof vFunc === 'function')) {
      vFunc = createFunc(vFunc);
    }
    if (!isEmpty(value) && !vFunc(formValues, value)) {
      return new Error((opt.message) || '上下文检查错误');
    }
  } catch (err) {
    return err;
  }
  return null;
};

export default validator;
