var hwver = '';
function reven() {
    dis = !getelem('unlock').checked || !hwver;
    getelem('setrev').disabled = dis;
}
function brev(ver,dover = true) {
    const bsel = getelem('boardrevs');
    const other = bsel.querySelector('option.other').value;
    hwver = ver && ver.match(/^MAX80 v(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*( [a-zA-Z0-9]+)?$/) ? ver : '';
    if (dover)
	getelem('ver').value = ver == other ? ver : hwver;
    bsel.value = hwver;
    if (bsel.selectedOptions.length == 0)
	bsel.value = other;
    reven();
}
function brn() { brev(event.target.selectedOptions[0].value); }
function brt() { brev(event.target.value,false); }
function bropen(ul) {
    ulchk = getelem('unlock');
    ulchk.checked = ul = (ul == undefined) ? ulchk.checked : ul;
    getelem('boardrevs').disabled = !ul;
    getelem('ver').disabled = !ul;
    getelem('warnrev').classList.toggle('hidden',!ul);
    reven();
}

fetchconfig('sys/getstatus')
    .then(map => brev(map.get('max80.hw.ver')))
    .catch(err => brev(undefined))
    .finally(() =>  {
	norev = !hwver;
	bropen(norev);
	getelem('norev').classList.toggle('hidden',!norev);
	getelem('upload.start').disabled = norev;
    });
