import { emailRegExp } from '@/modules/@common/constants/validation';

export const getErrorMessageForEmail = (value) => {
  const trimmedValue = value?.trim();
  let errorMessage = '';

  if (!trimmedValue) {
    errorMessage = 'Field cannot be empty';
  } else if (!emailRegExp.test(trimmedValue)) {
    errorMessage = 'Invalid email';
  }

  return errorMessage;
};

export const getErrorMessageForHttpsLink = (value) => {
  const trimmedValue = value?.trim();
  let errorMessage = '';

  if (!trimmedValue) {
    errorMessage = 'Field cannot be empty';
  } else if (!/^https:/.test(trimmedValue)) {
    errorMessage = 'URL must begin with https';
  } else if (!/^(https:\/\/)[a-z0-9]+([.-]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/gm.test(trimmedValue)) {
    errorMessage = 'Invalid URL';
  }

  return errorMessage;
};
