const nomeClienteFr = document.getElementById("nomeClienteFr");
const nifClienteFr = document.getElementById("nifClienteFr");
const trocoFr = document.getElementById("trocoFr");
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 trocoValid(small){
	trocoFr.className = "form-control is-valid";
	small.style.visibility = "visible";
	small.style.color = "#28a745";
	small.innerText = "Troco";
	btn.removeAttribute('disabled');
}

function trocoInvalid(small){
	trocoFr.className = "form-control is-invalid";
	small.style.visibility = "visible";
	small.style.color = "#dc3545";
	small.innerText = "Total";
	btn.setAttribute('disabled', 'disabled');
}


function nomeWarning(small){
	nomeClienteFr.className = "form-control is-warning";
	small.style.visibility = "visible";
	small.style.color = "#ffc107";
	small.innerText = "Campo Nome é Obrigatório!";
	btn.setAttribute('disabled', 'disabled');
}

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

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

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

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

nifClienteFr.addEventListener("keyup", function(){
	let small = nifClienteFr.parentElement.querySelectorAll("small")[1];
	if(nifClienteFr.value === ''){
		nifWarning(small);
	} else {
		nifValid(small);
	}
});

btn.addEventListener("click", function(){
	let smallNome = nomeClienteFr.parentElement.querySelectorAll("small")[1];
	let smallNif = nifClienteFr.parentElement.querySelectorAll("small")[1];
	if(nomeClienteFr.value == ''){
        nomeWarning(smallNome);
    } else {
		nomeValid(smallNome);
	}

	if(nifClienteFr.value == ''){
        nifWarning(smallNif);
    } else {
		nifValid(smallNif);
	}
});