/**
 * function to make validation in the forgot password
 * @param {*} email
 * @param {*} password
 * @param {*} passwordC
 * @param {*} emailError
 * @param {*} passwordError
 * @param {*} passwordCError
 */
export const validationForgotPassword = (
  email,
  password,
  passwordC,
  emailError,
  passwordError,
  passwordCError
) => {
  let isValid = true

  const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/

  // Email validation
  if (email.value === '') {
    isValid = false
    emailError.textContent = 'Email est requis'
  } else if (!emailPattern.test(email.value)) {
    isValid = false
    emailError.textContent = 'Entrez une adresse email valide'
  } else {
    emailError.textContent = ''
  }

  // Password validation
  if (password.value === '' || password.value.length < 6) {
    isValid = false
    passwordError.textContent = 'Le mot de passe doit comporter plus de 6 caractères.'
  } else {
    passwordError.textContent = ''
  }

  // Confirm Password validation
  if (passwordC.value !== password.value) {
    isValid = false
    passwordCError.textContent = 'Le mot de passe ne correspond pas.'
  } else {
    passwordCError.textContent = ''
  }

  return isValid
}
