'use strict';

const InterceptorHandler = require('./InterceptorHandler-09a1e84b.js');

class ValidatorEmail extends InterceptorHandler.InterceptorConfig {
  constructor() {
    super('validatorEmail');
  }
}
ValidatorEmail.id = 'validatorEmail';
const isValidEmail = (email) => /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(email).toLowerCase());
class ValidatorEmailHandler extends InterceptorHandler.InterceptorHandler {
  run(context, _values, field, value) {
    if (!value || !isValidEmail(value)) {
      return {
        error: context.strings.interceptors.validatorEmail.message.replace('{title}', field.errorTitle || field.title),
        value,
      };
    }
    return { value };
  }
}
InterceptorHandler.registerInterceptor(ValidatorEmail.id, (_config) => new ValidatorEmailHandler());

exports.ValidatorEmail = ValidatorEmail;
