const nome = document.getElementById("nome");
const codigo = document.getElementById("codigo");

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 nomeWarning(small){
	nome.className = "form-control is-warning";
	small.style.visibility = "visible";
	small.style.color = "#ffc107";
	small.innerText = "Campo Nome Completo é obrigatório!";
	btn.setAttribute('disabled', 'disabled');
}

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

nome.addEventListener("keyup", function(){
	let small = nome.parentElement.querySelectorAll("small")[1];
	if(nome.value === ''){
		nomeWarning(small);
	} else {
		nomeValid(small);
	}
});

function codigoWarning(small){
	codigo.className = "form-control is-warning";
	small.style.visibility = "visible";
	small.style.color = "#ffc107";
	small.innerText = "Campo Código é obrigatório!";
	btn.setAttribute('disabled', 'disabled');
}

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

codigo.addEventListener("keyup", function(){
	let small = codigo.parentElement.querySelectorAll("small")[1];
	if(codigo.value === ''){
		codigoWarning(small);
	} else {
		codigoValid(small);
	}
});


btn.addEventListener("click", function(){
	let smallNome = nome.parentElement.querySelectorAll("small")[1];
	let smallCodigo = codigo.parentElement.querySelectorAll("small")[1];
	if(nome.value == ''){
        nomeWarning(smallNome);
    } else {
		nomeValid(smallNome);
	}
	if(codigo.value == ''){
        codigoWarning(smallCodigo);
    } else {
		codigoValid(smallCodigo);
	}
});