/**
 * function to validate the email and password input
 *
 * @param {any} userNameRef
 * @param {any} password
 * @param {any} userNameError
 * @param {any} passwordError
 * @returns {boolean}
 */
export const ValidationLogin = (userNameRef, password, userNameError, passwordError) => {
  let isValid = true

  // Validate username
  if (userNameRef.value == '' || userNameRef.value == null) {
    isValid = false
    userNameError.textContent = "Entrer un nom d'utilisateur"
  }
  // Validate username
  else if (password.value == '' || password.value.length < 6) {
    passwordError.textContent = `mot de passe doit être plus de 6 caractères.`
    isValid = false
  } else {
    isValid = true
    userNameError.textContent = ''
    passwordError.textContent = ''
  }

  // remake varification username
  if (userNameRef.value !== '') {
    userNameError.textContent = ''
  }

  // remake varification password
  if (password.value.length > 6) {
    passwordError.textContent = ''
  } else {
    passwordError.textContent = `mot de passe doit être plus de 6 caractères.`
  }

  return isValid
}

/**
 * function to use when user submit an invalid information
 *
 * @param {any} userNameError
 */
export const invalidCredential = (userNameError, textC) => {
  userNameError.textContent = textC
}
