export function FileValidator(files) {
  const allowedFileTypes = 'image.*';
  return {
    validate: (value) => {
      if (value.length === 0) {
        return false;
      }
      else if (value.length > 1) {
        return false;
      }
      else if (value[0].type.match(allowedFileTypes).length <= 0) {
        return false;
      }
      else {
        return true;
      }
    },
    errorMessage: files.length === 0 ? 'No image uploaded' :
      files.length > 1 ? 'You can only upload one image at a time.' :
        files[0].type.match(allowedFileTypes).length <= 0 ? 'File type is not allowed.'
          : ''
  };
}
export function getLengthValidator(min, max) {
  return {
    validate: (value) => {
      if (!value || value === '') {
        return false;
      }
      if (min && max) {
        return min <= value.length && value.length <= max;
      }
      else if (min) {
        return min <= value.length;
      }
      else if (max) {
        return value.length <= max;
      }
      else {
        return true;
      }
    },
    errorMessage: min && max ? `You must enter between ${min} and ${max} characters`
      : min ? `You must enter atleast ${min} characters`
        : max ? `You must enter less than ${max} characters` : ''
  };
}
export function getCommitmentValidator(min) {
  return {
    validate: (value) => {
      if (!value || value === '') {
        return false;
      }
      if (min) {
        return min <= parseInt(value);
      }
      else {
        return true;
      }
    },
    errorMessage: min ? `Your commitment level must be atleast ${min}` : ''
  };
}
