"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = tooLong;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _utils = require("../../utils");

var _ValidationResult = _interopRequireDefault(require("../ValidationResult"));

var _localeContext = require("../../locale-context");

function tooLong(value, validatorBaseProps, getProp) {
  if (!(0, _utils.isEmpty)(value)) {
    var maxLength = getProp('maxLength');

    if (maxLength !== undefined && maxLength > 0) {
      var _value$toString = value.toString(),
          length = _value$toString.length;

      if (length > maxLength) {
        var injectionOptions = {
          maxLength: maxLength,
          length: length
        };
        var ruleName = 'tooLong';

        var _ref = getProp('defaultValidationMessages') || {},
            _ref$ruleName = _ref[ruleName],
            validationMessage = _ref$ruleName === void 0 ? (0, _localeContext.$l)('Validator', 'too_long') : _ref$ruleName;

        return new _ValidationResult["default"]({
          validationProps: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, validatorBaseProps), {}, {
            maxLength: maxLength
          }),
          validationMessage: validationMessage,
          injectionOptions: injectionOptions,
          value: value,
          ruleName: ruleName
        });
      }
    }
  }

  return true;
}
//# sourceMappingURL=tooLong.js.map
