import { r as registerInterceptor, I as InterceptorConfig, a as InterceptorHandler } from './InterceptorHandler-6474bcf4.js';

class ValidatorLength extends InterceptorConfig {
  constructor(min, max) {
    super('validatorLength');
    this.min = min;
    this.max = max;
  }
}
ValidatorLength.id = 'validatorLength';
class ValidatorLengthHandler extends InterceptorHandler {
  constructor(config) {
    super();
    this.config = config;
  }
  run(context, _, field, value) {
    const { max, min } = this.config;
    if (!min && !max) {
      return { value };
    }
    if (typeof value === 'string' || value instanceof String) {
      return validateString(context, field, value, min, max);
    }
    else if (value instanceof Array) {
      return validateArray(context, field, value, min, max);
    }
    return { value };
  }
}
function validateArray(context, field, value, min, max) {
  if (min && (!value || value.length < min)) {
    return {
      error: context.strings.interceptors.validatorLength.messageMinItems
        .replace('{title}', field.errorTitle || field.title)
        .replace('{min}', min),
      value,
    };
  }
  if (max && (value && value.length > max)) {
    return {
      error: context.strings.interceptors.validatorLength.messageMaxItems
        .replace('{title}', field.errorTitle || field.title)
        .replace('{max}', max),
      value,
    };
  }
  return { value };
}
function validateString(context, field, value, min, max) {
  if (min && (!value || value.length < min)) {
    return {
      error: context.strings.interceptors.validatorLength.messageMinChars
        .replace('{title}', field.errorTitle || field.title)
        .replace('{min}', min),
      value,
    };
  }
  if (max && (value && value.length > max)) {
    return {
      error: context.strings.interceptors.validatorLength.messageMaxChars
        .replace('{title}', field.errorTitle || field.title)
        .replace('{max}', max),
      value,
    };
  }
  return { value };
}
registerInterceptor(ValidatorLength.id, (config) => new ValidatorLengthHandler(config));

export { ValidatorLength as V };
