/**
 * function to use to validate the add admin
 * @param {*} username
 * @param {*} email
 * @param {*} password
 * @param {*} usernameError
 * @param {*} emailError
 * @param {*} passwordError
 * @returns Boolean
 */
const validationAddAdmin = (
  username,
  email,
  password,
  usernameError,
  emailError,
  passwordError
) => {
  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 = ''
  }

  // username validation
  if (username.value === '') {
    isValid = false
    usernameError.textContent = 'username réquis.'
  } else {
    usernameError.textContent = ''
  }

  return isValid
}

export default validationAddAdmin
