//-		DS2 core (c) 2024 Alexander McIlwraith 
//-		Licensed under CC BY-SA 4.0 

function flip(e) {
	let sw = e.currentTarget;
	switch(sw.getAttribute("aria-checked")) {
		case "true": 
			sw.setAttribute("aria-checked", "false");
		break;
		case "false": 
			sw.setAttribute("aria-checked", "true");
		break;
	}
};


function init(callback){
	let sw = document.querySelectorAll("[role='switch']");
	for (let i=0; i < sw.length; i++) {
		sw[i].innerHTML = "<span></span>";
		sw[i].setAttribute("aria-checked", "false");
		sw[i].setAttribute("tabindex", "0");
		sw[i].addEventListener("click", flip, false);
		sw[i].addEventListener("keypress", flip, false);
	}
}

export {init};