// JS part for esp32 server_http_ws template
// Copyright by Anthony Vogelaar, Perth Scotland
// rev 0.10  2025-12-12 initial release

// ===================== globals =============================

const	colors	= ["Red", "Yellow", "Lime", "LightSkyBlue"]
const	btns	= [document.getElementById("btn0"),
                   document.getElementById("btn1"),
                   document.getElementById("btn2"),
                   document.getElementById("btn3")]

// ======================= home page ===========================

// set four leds as specified in sts (array / list)
function updatePage(sts) {
    if (sts.length == 4) {
        for (var i = 0; i < 4; i++) {
            if (sts[i] == 1) btns[i].style.backgroundColor = colors[i]
            else             btns[i].style.backgroundColor = "teal"
        }
    }
}


function onBtn(ev) {
    wsSend(this.id)		// send button id to server
}

// ========================= main ==============================

function onLoad(ev) {
    for (var i = 0; i<btns.length; i++) {
        btns[i].addEventListener("click", onBtn)
    }
    wsock.onmessage = wsOnMessage
}


window.addEventListener("load", onLoad)

// ========================= end ==============================
