const tipoMatricula = document.getElementById("tipoMatricula");
const nota = document.getElementById("nota");

const btn = document.getElementById("btn-submit");
console.log("Cheguei!");

let numberRegExp = new RegExp('^[0-9-() ]+$');
let letterRegExp = new RegExp('^[a-zA-Z ]+$');
let biRegExp = new RegExp('^[a-zA-Z0-9]+$');
let emailRegExp = new RegExp('^[A-Za-z0-9._-]{3,}@[A-Za-z]{3,}[.]{1}[A-Za-z.]{2,6}$');
//document.querySelector("#idClasse").classList.add("is-invalidoooooo");

console.log('Pegar os smalls: ', document.querySelector('.form-group small'));

function tipoMatriculaWarning(small){
	tipoMatricula.className = "form-control is-warning";
	small.style.visibility = "visible";
	small.style.color = "#ffc107";
	small.innerText = "Campo Tipo Matrícula é obrigatório!";
	btn.setAttribute('disabled', 'disabled');
}

function tipoMatriculaValid(small){
	tipoMatricula.className = "form-control is-valid";
	btn.removeAttribute('disabled');
	small.style.visibility = "hidden";
}

tipoMatricula.addEventListener("keyup", function(){
	let small = tipoMatricula.parentElement.querySelectorAll("small")[1];
	if(tipoMatricula.value === ''){
		tipoMatriculaWarning(small);
	} else {
		tipoMatriculaValid(small);
	}
});

function notaWarning(small){
	nota.className = "form-control";
	small.style.visibility = "hidden";
	btn.removeAttribute('disabled');
}

function notaValid(small){
	nota.className = "form-control is-valid";
	btn.removeAttribute('disabled');
	small.style.visibility = "hidden";
}

nota.addEventListener("keyup", function(){
	let small = nota.parentElement.querySelectorAll("small")[1];
	if(nota.value === ''){
		notaWarning(small);
	} else {
		notaValid(small);
	}
});


btn.addEventListener("click", function(){
	let smalltipoMatricula = tipoMatricula.parentElement.querySelectorAll("small")[1];
	let smallNota = nota.parentElement.querySelectorAll("small")[1];
	if(tipoMatricula.value == ''){
        tipoMatriculaWarning(smalltipoMatricula);
    } else {
		tipoMatriculaValid(smalltipoMatricula);
	}
	if(nota.value == ''){
        notaWarning(smallNota);
    } else {
		notaValid(smallNota);
	}
});