const boletosDiv = document.getElementById("boletos");
let seleccion = null;
let vendidos = JSON.parse(localStorage.getItem("vendidos")) || {};
for (let i = 1; i <= 1000; i++) {
let num = i.toString().padStart(3, "0");
let div = document.createElement("div");
div.textContent = num;
div.className = "boleto";
if (vendidos[num]) div.classList.add("vendido");
div.onclick = () => {
if (div.classList.contains("vendido")) return;
document.querySelectorAll(".boleto").forEach(b => b.classList.remove("seleccionado"));
div.classList.add("seleccionado");
seleccion = num;
};
boletosDiv.appendChild(div);
}
function comprar() {
let nombre = document.getElementById("nombre").value;
let telefono = document.getElementById("telefono").value;
if (!nombre || !telefono || !seleccion) {
alert("Completa todos los datos y elige un boleto");
return;
}
vendidos[seleccion] = { nombre, telefono };
localStorage.setItem("vendidos", JSON.stringify(vendidos));
let mensaje = Hola, soy ${nombre}%0ABoleto: ${seleccion}%0APrecio: $250 MXN%0ATeléfono: ${telefono};
let url = https://wa.me/5218135535711?text=${mensaje};
window.open(url, "_blank");
location.reload();
}