-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarber.html
More file actions
265 lines (248 loc) · 13.4 KB
/
Copy pathbarber.html
File metadata and controls
265 lines (248 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Barber Dashboard — Bossman</title>
<link rel="stylesheet" href="brand.css">
<style>
body { padding: 1rem; }
.page { max-width: 420px; margin: 0 auto; display: flex; flex-direction: column; gap: 1rem; }
.card { background: var(--moss); border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); padding: 1.25rem; }
.header-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; color: var(--cream); }
.sub { color: var(--cream-dim); font-size: 0.78rem; margin-top: 0.15rem; letter-spacing: 0.06em; text-transform: uppercase; }
.toggle { padding: 0.4rem 0.95rem; border-radius: 999px; border: 1px solid var(--line); font-size: 0.8rem; font-weight: 600; cursor: pointer; font-family: var(--sans); }
.toggle.active { background: rgba(126,126,56,0.25); color: var(--gold-bright); border-color: var(--olive); }
.toggle.inactive { background: var(--pine); color: var(--cream-dim); }
.stats { display: flex; gap: 0.75rem; margin-top: 1rem; }
.stat { flex: 1; background: var(--pine); border: 1px solid var(--line); border-radius: 0.75rem; padding: 0.8rem; text-align: center; }
.stat-val { font-family: var(--serif); font-size: 1.7rem; font-weight: 800; color: var(--gold); }
.stat.gray .stat-val { color: var(--cream); }
.stat-label { font-size: 0.68rem; color: var(--cream-dim); margin-top: 0.15rem; letter-spacing: 0.06em; text-transform: uppercase; }
.serving-card { background: linear-gradient(135deg, var(--gold) 0%, var(--gold-bright) 100%); border-radius: 1rem; padding: 1rem 1.25rem; }
.serving-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: rgba(14,40,24,0.65); margin-bottom: 0.4rem; }
.serving-row { display: flex; align-items: center; justify-content: space-between; }
.serving-name { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; color: var(--pine); }
.serving-phone { font-size: 0.85rem; color: rgba(14,40,24,0.7); margin-top: 0.1rem; }
.icon-btns { display: flex; gap: 0.5rem; }
.icon-btn { background: var(--pine); border: none; border-radius: 0.6rem; padding: 0.5rem 0.6rem; cursor: pointer; font-size: 1.1rem; line-height: 1; text-decoration: none; display: inline-flex; align-items: center; }
/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; padding: 1.5rem; z-index: 100; }
.modal { background: var(--moss); border: 1px solid var(--line); border-radius: 1rem; padding: 1.5rem; width: 100%; max-width: 300px; }
.modal h3 { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; color: var(--cream); margin-bottom: 0.35rem; }
.modal p { font-size: 0.82rem; color: var(--cream-dim); margin-bottom: 1rem; }
.duration-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1.25rem; }
.duration-row button { width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 1.5px solid var(--fern); background: var(--pine); font-size: 1.2rem; font-weight: 700; cursor: pointer; color: var(--cream); }
.duration-row input { flex: 1; text-align: center; border: 1.5px solid var(--fern); background: var(--pine); border-radius: 0.6rem; padding: 0.5rem; font-size: 1.3rem; font-weight: 700; color: var(--cream); font-family: var(--serif); }
.duration-row span { font-size: 0.82rem; color: var(--cream-dim); white-space: nowrap; }
.modal-btns { display: flex; gap: 0.5rem; }
.modal-btns button { flex: 1; padding: 0.75rem; border-radius: 0.6rem; border: none; font-size: 0.92rem; font-weight: 600; cursor: pointer; font-family: var(--sans); }
.btn-cancel { background: var(--pine); color: var(--cream-dim); border: 1px solid var(--line) !important; }
.btn-confirm { background: var(--gold); color: var(--pine); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.section-title { font-family: var(--serif); font-weight: 700; color: var(--cream); font-size: 1.05rem; }
.call-btn { display: flex; align-items: center; gap: 0.4rem; background: var(--gold); color: var(--pine); border: none; border-radius: 0.6rem; padding: 0.5rem 1rem; font-size: 0.85rem; font-weight: 600; cursor: pointer; font-family: var(--sans); }
.call-btn:hover { background: var(--gold-bright); }
.queue-item { background: var(--moss); border: 1px solid var(--line); border-radius: 0.75rem; padding: 0.85rem 1rem; display: flex; align-items: center; justify-content: space-between; }
.queue-left { display: flex; align-items: center; gap: 0.75rem; }
.queue-num { width: 2rem; height: 2rem; border-radius: 50%; background: var(--pine); border: 1px solid var(--fern); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; color: var(--gold); flex-shrink: 0; }
.queue-name { font-weight: 600; color: var(--cream); font-size: 0.95rem; }
.queue-phone { font-size: 0.78rem; color: var(--cream-dim); margin-top: 0.1rem; }
.queue-actions { display: flex; gap: 0.25rem; }
.q-btn { background: none; border: none; cursor: pointer; padding: 0.3rem; font-size: 1.1rem; opacity: 0.75; }
.q-btn:hover { opacity: 1; }
.empty { text-align: center; color: var(--cream-dim); padding: 2.5rem 1rem; font-size: 0.92rem; letter-spacing: 0.03em; }
.queue-stack { display: flex; flex-direction: column; gap: 0.5rem; }
.refresh-note { text-align: center; font-size: 0.68rem; color: var(--cream-dim); opacity: 0.6; padding-top: 0.5rem; letter-spacing: 0.05em; }
</style>
</head>
<body>
<div class="page">
<div class="card">
<div class="header-row">
<div>
<h1 id="barber-name">Loading…</h1>
<p class="sub" id="clock">🕐 --:--:-- MYT</p>
</div>
<button class="toggle active" id="toggle-btn" onclick="toggleActive()">Active</button>
</div>
<div class="stats">
<div class="stat">
<div class="stat-val" id="stat-waiting">0</div>
<div class="stat-label">waiting</div>
</div>
<div class="stat gray">
<div class="stat-val" id="stat-wait">~0m</div>
<div class="stat-label">total wait</div>
</div>
</div>
</div>
<div id="serving-section" class="hidden serving-card">
<div class="serving-label">Currently Serving</div>
<div class="serving-row">
<div>
<div class="serving-name" id="serving-name">-</div>
<div class="serving-phone" id="serving-phone">-</div>
</div>
<div class="icon-btns">
<a class="icon-btn" id="serving-call" href="#" title="Call">📞</a>
<a class="icon-btn" id="serving-wa" href="#" target="_blank" title="WhatsApp">💬</a>
<button class="icon-btn" onclick="markStatus(servingId, 'done')" title="Done">✅</button>
<button class="icon-btn" onclick="markStatus(servingId, 'no_show')" title="No show">❌</button>
</div>
</div>
<p style="font-size:0.72rem;color:rgba(14,40,24,0.7);margin-top:0.6rem;letter-spacing:0.02em;">Not here? Tap 📞 to call or 💬 to WhatsApp them.</p>
</div>
<div class="modal-overlay hidden" id="duration-modal">
<div class="modal">
<h3>How long is this cut?</h3>
<p>Set the time so the queue shows accurate wait times.</p>
<div class="duration-row">
<button onclick="adjustDuration(-5)">−</button>
<input type="number" id="duration-input" value="30" min="5" max="120">
<span>minutes</span>
<button onclick="adjustDuration(+5)">+</button>
</div>
<div class="modal-btns">
<button class="btn-cancel" onclick="closeModal()">Cancel</button>
<button class="btn-confirm" onclick="confirmCallNext()">Call & Start</button>
</div>
</div>
</div>
<div>
<div class="section-header">
<span class="section-title">Queue</span>
<button class="call-btn hidden" id="call-btn" onclick="openCallModal()">🔔 Call Next</button>
</div>
<div class="queue-stack" id="queue-list">
<div class="empty">Loading queue…</div>
</div>
<p class="refresh-note">Auto-refreshes every 10 seconds</p>
</div>
</div>
<script src="api.js"></script>
<script>
var PIN = new URLSearchParams(window.location.search).get("pin") || "";
var barber = null;
var servingId = null;
function remainingCut(serving, avg) {
if (!serving) return 0;
var duration = serving.durationMinutes || avg;
if (!serving.calledAt) return duration;
var elapsedMin = (Date.now() - new Date(serving.calledAt).getTime()) / 60000;
return Math.max(0, Math.round(duration - elapsedMin));
}
function tickClock() {
var el = document.getElementById("clock");
if (!el) return;
var t = new Date().toLocaleTimeString("en-GB", { timeZone: "Asia/Kuala_Lumpur", hour: "2-digit", minute: "2-digit", second: "2-digit" });
el.textContent = "🕐 " + t + " MYT";
}
setInterval(tickClock, 1000);
function init() {
call({ action: "getBarberByPin", pin: PIN }).then(function(b) {
if (!b || b.error) {
document.querySelector(".page").innerHTML = "<div class='card'><p style='color:#e88'>Invalid PIN. Check your link.</p></div>";
return;
}
barber = b;
barber.avgMinutes = 35; // flat average wait estimate per customer
document.getElementById("barber-name").textContent = b.name;
updateToggleBtn();
loadQueue();
setInterval(loadQueue, 10000);
}).catch(function() {
document.querySelector(".page").innerHTML = "<div class='card'><p style='color:#e88'>Failed to load. Please refresh.</p></div>";
});
}
function loadQueue() {
if (!barber) return;
call({ action: "getBarberQueue", pin: PIN }).then(renderQueue).catch(function() {});
}
function renderQueue(queue) {
queue = queue || [];
var waiting = queue.filter(function(q) { return q.status === "waiting"; });
var serving = queue.find(function(q) { return q.status === "called"; });
var avg = barber ? barber.avgMinutes || 30 : 30;
var remaining = remainingCut(serving, avg);
// Wait for the last person in line (time until the queue clears)
var lastWait = waiting.length === 0 ? 0 : (serving ? remaining : 0) + (waiting.length - 1) * avg;
document.getElementById("stat-waiting").textContent = waiting.length;
document.getElementById("stat-wait").textContent = "~" + lastWait + "m";
var servingSection = document.getElementById("serving-section");
if (serving) {
servingId = serving.id;
document.getElementById("serving-name").textContent = serving.customerName;
document.getElementById("serving-phone").textContent = serving.phone;
var digits = String(serving.phone).replace(/\D/g, "");
document.getElementById("serving-call").href = "tel:" + digits;
document.getElementById("serving-wa").href = "https://wa.me/" + digits;
servingSection.classList.remove("hidden");
} else {
servingId = null;
servingSection.classList.add("hidden");
}
var callBtn = document.getElementById("call-btn");
if (!serving && waiting.length > 0) callBtn.classList.remove("hidden");
else callBtn.classList.add("hidden");
var list = document.getElementById("queue-list");
if (waiting.length === 0 && !serving) {
list.innerHTML = "<div class='empty'>Queue is empty — enjoy the break ☕</div>";
return;
}
list.innerHTML = "";
waiting.forEach(function(entry, i) {
var waitMins = (serving ? remaining : 0) + i * avg;
var item = document.createElement("div");
item.className = "queue-item";
item.innerHTML =
'<div class="queue-left">' +
'<div class="queue-num">' + (i + 1) + '</div>' +
'<div><div class="queue-name">' + entry.customerName + '</div>' +
'<div class="queue-phone">~' + waitMins + ' min wait · ' + entry.phone + '</div></div>' +
'</div>' +
'<div class="queue-actions">' +
'<button class="q-btn" onclick="markStatus(\'' + entry.id + '\',\'done\')">✅</button>' +
'<button class="q-btn" onclick="markStatus(\'' + entry.id + '\',\'no_show\')">❌</button>' +
'</div>';
list.appendChild(item);
});
}
function openCallModal() {
document.getElementById("duration-input").value = 30;
document.getElementById("duration-modal").classList.remove("hidden");
}
function closeModal() { document.getElementById("duration-modal").classList.add("hidden"); }
function adjustDuration(delta) {
var inp = document.getElementById("duration-input");
inp.value = Math.max(5, Math.min(120, (parseInt(inp.value) || 30) + delta));
}
function confirmCallNext() {
if (!barber) return;
var mins = parseInt(document.getElementById("duration-input").value) || 30;
closeModal();
document.getElementById("call-btn").textContent = "Calling…";
call({ action: "callNext", pin: PIN, durationMinutes: mins })
.then(loadQueue).catch(loadQueue);
}
function markStatus(id, status) {
if (!id || !barber) return;
call({ action: "setStatus", pin: PIN, id: id, status: status })
.then(loadQueue).catch(function() {});
}
function toggleActive() {
if (!barber) return;
call({ action: "toggleActive", pin: PIN }).then(function(res) {
if (res && typeof res.isActive !== "undefined") { barber.isActive = res.isActive; updateToggleBtn(); }
}).catch(function() {});
}
function updateToggleBtn() {
var btn = document.getElementById("toggle-btn");
btn.textContent = barber.isActive ? "Active" : "Inactive";
btn.className = "toggle " + (barber.isActive ? "active" : "inactive");
}
init();
</script>
</body>
</html>