|
1 | 1 | let selectedBooth = null; |
2 | 2 | let selectedVibe = null; |
3 | 3 |
|
4 | | -function setActive(containerId, datasetKey, value) { |
5 | | - const container = document.getElementById(containerId); |
6 | | - const buttons = container.querySelectorAll("button"); |
7 | | - buttons.forEach(btn => { |
8 | | - btn.classList.toggle("active", btn.dataset[datasetKey] === value); |
9 | | - }); |
| 4 | +const boothButtons = document.querySelectorAll("#booths button"); |
| 5 | +const vibeButtons = document.querySelectorAll("#vibes button"); |
| 6 | + |
| 7 | +const detailEl = document.getElementById("detail"); |
| 8 | +const ticketEl = document.getElementById("ticket"); |
| 9 | +const placeOrderBtn = document.getElementById("placeOrder"); |
| 10 | +const copyBtn = document.getElementById("copyBtn"); |
| 11 | +const confirmText = document.getElementById("confirmText"); |
| 12 | + |
| 13 | +function setActive(buttons, target){ |
| 14 | + buttons.forEach(b => b.classList.remove("active")); |
| 15 | + target.classList.add("active"); |
10 | 16 | } |
11 | 17 |
|
12 | | -document.getElementById("booths").addEventListener("click", (e) => { |
13 | | - const btn = e.target.closest("button"); |
14 | | - if (!btn) return; |
15 | | - selectedBooth = btn.dataset.booth; |
16 | | - setActive("booths", "booth", selectedBooth); |
| 18 | +boothButtons.forEach(btn => { |
| 19 | + btn.addEventListener("click", () => { |
| 20 | + selectedBooth = btn.dataset.booth; |
| 21 | + setActive(boothButtons, btn); |
| 22 | + confirmText.textContent = ""; |
| 23 | + }); |
17 | 24 | }); |
18 | 25 |
|
19 | | -document.getElementById("vibes").addEventListener("click", (e) => { |
20 | | - const btn = e.target.closest("button"); |
21 | | - if (!btn) return; |
22 | | - selectedVibe = btn.dataset.vibe; |
23 | | - setActive("vibes", "vibe", selectedVibe); |
| 26 | +vibeButtons.forEach(btn => { |
| 27 | + btn.addEventListener("click", () => { |
| 28 | + selectedVibe = btn.dataset.vibe; |
| 29 | + setActive(vibeButtons, btn); |
| 30 | + confirmText.textContent = ""; |
| 31 | + }); |
24 | 32 | }); |
25 | 33 |
|
26 | | -document.getElementById("placeOrder").addEventListener("click", () => { |
27 | | - const detail = document.getElementById("detail").value.trim(); |
| 34 | +function buildTicket(){ |
| 35 | + const detail = (detailEl.value || "").trim(); |
| 36 | + return `Booth: ${selectedBooth || "(pick one)"}\nVibe: ${selectedVibe || "(pick one)"}\nDetail: ${detail || "(add one sentence)"}`; |
| 37 | +} |
| 38 | + |
| 39 | +placeOrderBtn.addEventListener("click", () => { |
| 40 | + const detail = (detailEl.value || "").trim(); |
28 | 41 |
|
29 | | - if (!selectedBooth || !selectedVibe || !detail) { |
30 | | - alert("Pick a booth, pick a vibe, and add one sentence."); |
| 42 | + if(!selectedBooth || !selectedVibe){ |
| 43 | + confirmText.textContent = "Pick a Booth and a Vibe first."; |
| 44 | + return; |
| 45 | + } |
| 46 | + if(detail.length === 0){ |
| 47 | + confirmText.textContent = "Add one sentence in the detail box."; |
31 | 48 | return; |
32 | 49 | } |
33 | 50 |
|
34 | | - const ticketText = |
35 | | -`Booth: ${selectedBooth} |
36 | | -Vibe: ${selectedVibe} |
37 | | -Detail: ${detail}`; |
| 51 | + const ticket = buildTicket(); |
| 52 | + ticketEl.textContent = ticket; |
38 | 53 |
|
39 | | - document.getElementById("ticket").textContent = ticketText; |
40 | | - document.getElementById("copyBtn").style.display = "inline-block"; |
41 | | - document.getElementById("status").style.display = "block"; |
| 54 | + copyBtn.style.display = "inline-block"; |
| 55 | + confirmText.textContent = "Order received. The bartender is working."; |
42 | 56 | }); |
43 | 57 |
|
44 | | -document.getElementById("copyBtn").addEventListener("click", async () => { |
45 | | - const text = document.getElementById("ticket").textContent; |
46 | | - try { |
| 58 | +copyBtn.addEventListener("click", async () => { |
| 59 | + const text = ticketEl.textContent.trim(); |
| 60 | + if(!text){ |
| 61 | + confirmText.textContent = "No ticket to copy yet."; |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + try{ |
47 | 66 | await navigator.clipboard.writeText(text); |
48 | | - alert("Ticket copied. Paste it into the Bronzed Derby chat."); |
49 | | - } catch { |
50 | | - alert("Couldn’t auto-copy. Manually select the ticket text and copy it."); |
| 67 | + confirmText.textContent = "Ticket copied. Paste it into ChatGPT (or your House Generator prompt)."; |
| 68 | + }catch(e){ |
| 69 | + // Fallback if clipboard permission fails |
| 70 | + confirmText.textContent = "Copy failed. Select the ticket text and copy manually."; |
51 | 71 | } |
52 | 72 | }); |
0 commit comments