Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1079 lines (960 loc) · 56.6 KB
/
Copy pathindex.html
File metadata and controls
1079 lines (960 loc) · 56.6 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<title>TIMERTHING</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="/socket.io/socket.io.js"></script>
</head>
<body class="bg-black text-white min-h-screen font-sans">
<!-- Landing Page -->
<div id="setupView" class="min-h-screen flex items-center justify-center">
<div class="container max-w-2xl px-6 py-12 text-center">
<h1 class="text-8xl font-black mb-12 tracking-tighter">TIMER<span class="text-red-600">THING</span></h1>
<button onclick="enterSite()" class="bg-red-600 hover:bg-red-700 text-white font-black px-16 py-6 rounded-2xl text-2xl transition-all active:scale-95 shadow-2xl shadow-red-900/20">
ENTER
</button>
</div>
</div>
<!-- Race List View -->
<div id="listView" class="min-h-screen hidden p-8 flex flex-col bg-black overflow-x-hidden">
<div class="flex justify-between items-start w-full mb-16 px-4">
<h1 class="text-4xl font-black tracking-tighter">TIMER<span class="text-red-600">THING</span></h1>
<div class="relative z-50">
<button onclick="toggleLoginMenu()" id="loginBtn" class="bg-zinc-900 border border-zinc-800 px-8 py-3 rounded-xl text-xs font-black uppercase tracking-widest hover:border-red-600 transition-all active:scale-95 shadow-xl">
Login
</button>
<!-- Login Dropdown -->
<div id="loginDropdown" class="absolute top-full right-0 mt-3 w-64 bg-zinc-900 border border-zinc-800 rounded-2xl overflow-hidden hidden shadow-[0_30px_60px_rgba(0,0,0,0.8)] border border-white/5">
<button onclick="showModal('manageModal'); toggleLoginMenu()" class="w-full px-6 py-4 text-left text-[10px] font-black uppercase tracking-widest hover:bg-red-600 transition-all border-b border-zinc-800/50">Manage Race</button>
<button onclick="showModal('joinModal'); toggleLoginMenu()" class="w-full px-6 py-4 text-left text-[10px] font-black uppercase tracking-widest hover:bg-zinc-800 transition-all">Join Camera</button>
</div>
</div>
</div>
<div class="max-w-4xl mx-auto w-full flex-1 pb-20">
<h2 class="text-zinc-500 font-bold uppercase tracking-widest text-xs mb-4">Event Registry</h2>
<div id="raceListContainer" class="space-y-3">
<!-- Races go here -->
</div>
</div>
</div>
<!-- Admin Dashboard -->
<div id="adminDashboard" class="min-h-screen hidden p-8 flex flex-col bg-black">
<div class="flex justify-between items-center mb-12">
<h1 class="text-4xl font-black tracking-tighter uppercase italic">Admin <span class="text-red-600">Panel</span></h1>
<button onclick="location.reload()" class="text-zinc-500 hover:text-white text-xs font-bold uppercase tracking-widest">Logout</button>
</div>
<div class="max-w-5xl mx-auto w-full space-y-8">
<div class="bg-zinc-900 border border-zinc-800 p-8 rounded-3xl flex justify-between items-center shadow-2xl">
<div>
<h2 class="text-2xl font-black uppercase tracking-tight">System Ready</h2>
<p class="text-zinc-500 text-sm">Initialize a new timing room to start a race</p>
</div>
<button onclick="showModal('createRaceModal')" class="bg-red-600 hover:bg-red-700 text-white font-black px-8 py-4 rounded-xl transition-all shadow-lg shadow-red-900/20">CREATE NEW RACE</button>
</div>
<div class="space-y-4">
<h3 class="text-zinc-500 font-bold uppercase tracking-widest text-xs">Manage Past Records</h3>
<div id="adminRaceList" class="space-y-3"></div>
</div>
</div>
</div>
<!-- Manage Modal -->
<div id="manageModal" class="fixed inset-0 z-50 flex items-center justify-center bg-black/90 backdrop-blur-sm hidden p-4">
<div class="bg-zinc-900 border border-zinc-800 p-8 rounded-3xl w-full max-w-md relative shadow-2xl">
<button onclick="hideModal('manageModal')" class="absolute top-4 right-4 text-zinc-500 hover:text-white">✕</button>
<h3 class="text-xl font-black uppercase tracking-widest text-zinc-400 mb-6">Manager Login</h3>
<input type="password" id="managerCodeInput" placeholder="ACCESS CODE" class="w-full bg-black border border-zinc-800 rounded-xl px-4 py-4 text-center font-mono text-xl tracking-widest focus:outline-none focus:border-red-600 mb-4 transition-colors">
<button id="loginSubmitBtn" class="w-full py-4 bg-red-600 hover:bg-red-700 text-white font-bold rounded-xl transition-all active:scale-95 shadow-lg shadow-red-900/40">
LOGIN
</button>
</div>
</div>
<!-- Create Race Modal -->
<div id="createRaceModal" class="fixed inset-0 z-50 flex items-center justify-center bg-black/90 backdrop-blur-sm hidden p-4">
<div class="bg-zinc-900 border border-zinc-800 p-8 rounded-3xl w-full max-w-md relative shadow-2xl">
<button onclick="hideModal('createRaceModal')" class="absolute top-4 right-4 text-zinc-500 hover:text-white">✕</button>
<h3 class="text-xl font-black uppercase tracking-widest text-zinc-400 mb-6">New Race</h3>
<input type="text" id="raceNameInput" placeholder="RACE NAME (e.g. Finals 100m)" class="w-full bg-black border border-zinc-800 rounded-xl px-4 py-4 text-center font-bold text-sm mb-4 focus:outline-none focus:border-red-600">
<button id="createBtn" class="w-full py-4 bg-red-600 hover:bg-red-700 text-white font-bold rounded-xl transition-all">START TIMING ROOM</button>
</div>
</div>
<!-- Join Modal -->
<div id="joinModal" class="fixed inset-0 z-50 flex items-center justify-center bg-black/90 backdrop-blur-sm hidden p-4">
<div class="bg-zinc-900 border border-zinc-800 p-8 rounded-3xl w-full max-w-md relative shadow-2xl">
<button onclick="hideModal('joinModal')" class="absolute top-4 right-4 text-zinc-500 hover:text-white">✕</button>
<h3 class="text-xl font-black uppercase tracking-widest text-zinc-400 mb-6">Join Camera</h3>
<div class="flex flex-col gap-4">
<input type="text" id="joinCodeInput" placeholder="ROOM CODE" class="w-full bg-black border border-zinc-800 rounded-xl px-4 py-4 text-center font-mono text-xl tracking-widest uppercase focus:outline-none focus:border-red-600 transition-colors">
<button id="joinBtn" class="w-full py-4 bg-red-600 hover:bg-red-700 text-white font-bold rounded-xl transition-all active:scale-95 shadow-lg shadow-red-900/40">
CONNECT CAMERA
</button>
</div>
</div>
</div>
<!-- Main Room Dashboard -->
<div id="roomDash" style="display:none;" class="p-6 max-w-7xl mx-auto flex flex-col gap-6">
<!-- Header -->
<div class="flex flex-col md:flex-row justify-between items-center bg-zinc-900 p-6 rounded-2xl border border-zinc-800 gap-4">
<div>
<h1 id="activeRaceName" contenteditable="true" class="text-3xl font-black tracking-tighter focus:outline-none focus:text-red-600 transition-colors">TIMERTHING</h1>
<p class="text-zinc-500 text-xs font-bold uppercase tracking-widest">Room: <span id="codeDisplay" class="text-red-600"></span></p>
<div class="mt-1 flex items-center gap-2">
<span class="text-[10px] text-zinc-600 uppercase font-bold">Viewer Link:</span>
<span id="viewerCode" class="text-[10px] text-zinc-400 font-mono bg-black/50 px-2 py-0.5 rounded cursor-pointer hover:text-white transition-colors"></span>
</div>
</div>
<div class="flex items-center gap-4">
<div id="status" class="text-xs font-bold text-zinc-400 py-2 px-4 bg-zinc-800 rounded-xl">Waiting for Camera...</div>
<button id="startRaceBtn" class="bg-green-600 hover:bg-green-700 px-6 py-2 rounded-xl font-bold text-sm transition-all">START RACE</button>
<button id="stopRaceBtn" class="bg-amber-600 hover:bg-amber-700 px-6 py-2 rounded-xl font-bold text-sm transition-all hidden">STOP RACE</button>
<button id="endRaceBtn" class="bg-red-600 hover:bg-red-700 px-6 py-2 rounded-xl font-bold text-sm transition-all hidden">END RACE</button>
<button id="saveEditBtn" class="bg-blue-600 hover:bg-blue-700 px-6 py-2 rounded-xl font-bold text-sm transition-all hidden">SAVE CHANGES</button>
<button id="toggleHeatsBtn" class="bg-zinc-800 hover:bg-zinc-700 text-white px-6 py-2 rounded-xl font-bold text-sm transition-all">ENABLE HEATS</button>
<button id="manualSplitBtn" class="bg-zinc-100 text-black px-6 py-2 rounded-xl font-bold text-sm transition-all hidden">MANUAL SPLIT</button>
<div id="raceClock" class="font-mono text-2xl text-red-600 hidden">00:00.0</div>
</div>
</div>
<!-- Heat Controls -->
<div id="heatControlBar" class="bg-zinc-900 border border-zinc-800 p-4 rounded-2xl flex flex-wrap items-center justify-between gap-4 hidden">
<div class="flex items-center gap-4">
<span class="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">Heat Management:</span>
<div class="flex items-center gap-2">
<button id="prevHeatBtn" class="bg-zinc-800 text-white p-2 rounded-lg hover:bg-zinc-700 disabled:opacity-50">←</button>
<div class="bg-black px-4 py-1.5 rounded-lg border border-zinc-800 text-center min-w-[100px]">
<p class="text-[8px] text-zinc-500 uppercase font-black leading-none mb-1">Current Heat</p>
<span id="currentHeatDisplay" class="text-white font-black text-lg leading-none">1</span>
</div>
<button id="nextHeatBtn" class="bg-zinc-800 text-white p-2 rounded-lg hover:bg-zinc-700">→</button>
</div>
<button id="finishHeatBtn" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-xl font-bold text-[10px] uppercase transition-all hidden">End Heat & Next</button>
</div>
<div class="text-[10px] text-zinc-500 font-bold italic max-w-xs text-right">Each heat has its own start time. Laps for assigned runners are calculated relative to their heat's start.</div>
</div>
<!-- Audio Commands -->
<div class="bg-zinc-900 border border-zinc-800 p-4 rounded-2xl flex flex-wrap items-center justify-between gap-4">
<div class="flex items-center gap-4">
<span class="text-[10px] font-bold text-zinc-500 uppercase tracking-widest">Voice Protocol:</span>
<select id="audioTarget" class="bg-black border border-zinc-800 rounded-lg text-xs px-3 py-1.5 focus:outline-none focus:border-red-600">
<option value="manager">Manager Device</option>
<option value="camera">Camera Device</option>
</select>
</div>
<div class="flex items-center gap-2">
<button id="marksBtn" class="bg-zinc-800 hover:bg-zinc-700 text-white font-bold px-4 py-2 rounded-xl text-[10px] uppercase transition-all">Marks</button>
<button id="setBtn" class="bg-zinc-800 hover:bg-zinc-700 text-white font-bold px-4 py-2 rounded-xl text-[10px] uppercase transition-all">Set</button>
<button id="audioStartBtn" class="bg-red-600 hover:bg-red-700 text-white font-black px-6 py-2 rounded-xl text-[10px] uppercase shadow-lg shadow-red-900/20">Start Race</button>
<button id="falseStartBtn" class="bg-amber-600 hover:bg-amber-700 text-white font-black px-6 py-2 rounded-xl text-[10px] uppercase hidden">False Start</button>
</div>
</div>
<!-- Event Statistics Bar -->
<div id="eventStats" class="grid grid-cols-3 gap-4">
<div class="bg-zinc-900 border border-zinc-800 p-4 rounded-2xl text-center shadow-xl">
<p class="text-[10px] font-bold text-zinc-500 uppercase tracking-widest mb-1">Total Laps</p>
<p id="statLaps" class="text-2xl font-black text-white">0</p>
</div>
<div class="bg-zinc-900 border border-zinc-800 p-4 rounded-2xl text-center shadow-xl">
<p class="text-[10px] font-bold text-zinc-500 uppercase tracking-widest mb-1">Total Distance</p>
<p id="statMeters" class="text-2xl font-black text-red-600">0<span class="text-xs ml-1 text-zinc-500 font-bold uppercase">m</span></p>
</div>
<div class="bg-zinc-900 border border-zinc-800 p-4 rounded-2xl text-center shadow-xl">
<p class="text-[10px] font-bold text-zinc-500 uppercase tracking-widest mb-1">Miles Covered</p>
<p id="statMiles" class="text-2xl font-black text-white">0.00</p>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6">
<!-- Left: Start List & Stats -->
<div class="lg:col-span-4 space-y-6">
<!-- Start List -->
<div class="bg-zinc-900 rounded-2xl border border-zinc-800 p-6">
<h3 class="text-sm font-bold uppercase tracking-widest text-zinc-500 mb-4">Start List</h3>
<textarea id="nameInput" placeholder="Enter names (one per line)" class="w-full bg-black border border-zinc-800 rounded-xl p-3 text-sm focus:outline-none focus:border-red-600 h-32 mb-4"></textarea>
<div class="grid grid-cols-2 gap-3 mb-4">
<div class="space-y-1">
<label class="text-[8px] text-zinc-500 font-black uppercase tracking-widest">Lap Distance (m)</label>
<input type="number" id="lapDist" value="400" class="w-full bg-black border border-zinc-800 rounded-xl px-3 py-2 text-sm focus:outline-none">
</div>
<div class="space-y-1">
<label class="text-[8px] text-zinc-500 font-black uppercase tracking-widest">Min Split (s)</label>
<input type="number" id="minSplitTimeInput" value="5" min="0" step="0.5" class="w-full bg-black border border-zinc-800 rounded-xl px-3 py-2 text-sm focus:outline-none">
</div>
</div>
<button id="updateListBtn" class="w-full bg-zinc-100 text-black font-black py-3 rounded-xl text-xs uppercase tracking-widest active:scale-95 transition-all">Apply Settings</button>
</div>
<!-- Leaderboard -->
<div class="bg-zinc-900 rounded-2xl border border-zinc-800 p-6">
<h3 class="text-sm font-bold uppercase tracking-widest text-zinc-500 mb-4">Leaderboard</h3>
<div id="leaderboard" class="space-y-3">
<p class="text-zinc-600 text-xs italic text-center">No results yet...</p>
</div>
</div>
</div>
<!-- Right: Split Feed -->
<div class="lg:col-span-8 bg-zinc-900 rounded-2xl border border-zinc-800 p-6">
<h3 class="text-sm font-bold uppercase tracking-widest text-zinc-500 mb-4 tracking-widest">Live Detection Feed</h3>
<div id="results" class="grid grid-cols-1 md:grid-cols-2 gap-4 max-h-[70vh] overflow-y-auto pr-2"></div>
</div>
</div>
</div>
<script>
const socket = io();
let startList = [];
let allSplits = []; // { id, timestamp, image, runnerNames }
let calculatedLeaderboard = [];
let raceStartTime = null;
let isRaceStopped = false;
let raceStopTime = null;
let isHeatsEnabled = false;
let currentHeat = 1;
let heatData = {}; // { heatIdx: { startTime, stopTime } }
let timerInterval;
// let activeRoomId = null; // Renamed from currentRoomId for clarity with localStorage - not used
let currentRoomId = null;
let managerLoggedIn = false;
// Cookie Helpers
function setCookie(name, value, days) {
let expires = "";
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/; SameSite=Strict";
}
function getCookie(name) {
const nameEQ = name + "=";
const ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
const MANUAL_IMG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
// DOM Elements
const loginSubmitBtn = document.getElementById('loginSubmitBtn');
const createBtn = document.getElementById('createBtn');
const startRaceBtn = document.getElementById('startRaceBtn');
const stopRaceBtn = document.getElementById('stopRaceBtn');
const endRaceBtn = document.getElementById('endRaceBtn');
const saveEditBtn = document.getElementById('saveEditBtn');
const manualSplitBtn = document.getElementById('manualSplitBtn');
const updateListBtn = document.getElementById('updateListBtn');
const nameInput = document.getElementById('nameInput');
const toggleHeatsBtn = document.getElementById('toggleHeatsBtn');
const heatControlBar = document.getElementById('heatControlBar');
const currentHeatDisplay = document.getElementById('currentHeatDisplay');
const prevHeatBtn = document.getElementById('prevHeatBtn');
const audioStartBtn = document.getElementById('audioStartBtn');
const nextHeatBtn = document.getElementById('nextHeatBtn');
const finishHeatBtn = document.getElementById('finishHeatBtn');
const resultsDiv = document.getElementById('results');
const leaderboardDiv = document.getElementById('leaderboard');
const raceClock = document.getElementById('raceClock');
let editingPastRaceId = null;
function enterSite() {
document.getElementById('setupView').classList.add('hidden');
document.getElementById('listView').classList.remove('hidden');
socket.emit('get-races');
}
// Helper to update URL without refreshing
function setManagementUrl(type, id) {
const url = new URL(window.location.origin + window.location.pathname);
if (type && id) url.searchParams.set(type, id);
window.history.pushState({}, '', url);
}
// Function to initialize app state on page load
function initializeAppState() {
const urlParams = new URLSearchParams(window.location.search);
const manageId = urlParams.get('manage');
const editId = urlParams.get('edit');
// Check for manager login persistence
const storedManagerLogin = getCookie('managerLoggedIn');
if (storedManagerLogin === 'true') {
managerLoggedIn = true;
}
// If URL has a management or edit parameter, prioritize it
if (manageId || editId) {
document.getElementById('setupView').classList.add('hidden');
if (managerLoggedIn) {
if (editId) {
editingPastRaceId = editId;
socket.emit('get-race-data', editId);
} else {
currentRoomId = manageId;
socket.emit('get-race-data', manageId);
}
} else {
// Force login if trying to access a room via URL
document.getElementById('listView').classList.remove('hidden');
showModal('manageModal');
}
return;
}
if (managerLoggedIn) {
document.getElementById('setupView').classList.add('hidden');
document.getElementById('adminDashboard').classList.remove('hidden');
socket.emit('get-races');
} else {
}
}
document.addEventListener('DOMContentLoaded', initializeAppState);
function toggleLoginMenu() {
document.getElementById('loginDropdown').classList.toggle('hidden');
}
socket.on('races-list', (data) => {
const container = document.getElementById('raceListContainer');
const adminContainer = document.getElementById('adminRaceList');
container.innerHTML = '';
if (adminContainer) adminContainer.innerHTML = '';
// Live Races first
data.live.forEach(race => {
container.innerHTML += `
<div class="bg-zinc-900 border border-red-600/30 p-6 rounded-2xl flex justify-between items-center hover:bg-zinc-800 transition-all cursor-pointer" onclick="window.location.href='/viewer.html?room=${race.roomId}'">
<div>
<span class="text-[10px] bg-red-600 text-white px-2 py-0.5 rounded-full font-black uppercase tracking-tighter mb-2 inline-block">Live Race</span>
<h3 class="text-xl font-bold uppercase tracking-tight">${race.name}</h3>
</div>
<div class="text-red-600 font-mono text-sm">Room: ${race.roomId}</div>
</div>
`;
});
// Past Races
data.past.forEach(race => {
container.innerHTML += `
<div class="bg-zinc-900 border border-zinc-800 p-6 rounded-2xl flex justify-between items-center opacity-70 hover:opacity-100 transition-all">
<div>
<span class="text-[10px] bg-green-600 text-white px-2 py-0.5 rounded-full font-black uppercase tracking-tighter mb-2 inline-block">Done</span>
<h3 class="text-xl font-bold uppercase tracking-tight">${race.name}</h3>
<p class="text-[10px] text-zinc-500 font-bold">${new Date(race.date).toLocaleDateString()}</p>
</div>
<button onclick="window.location.href='/viewer.html?raceId=${race._id}'" class="text-xs font-bold text-zinc-400 border border-zinc-800 px-4 py-2 rounded-lg hover:border-white transition-all">VIEW RESULTS</button>
</div>
`;
if (managerLoggedIn && adminContainer) {
adminContainer.innerHTML += `
<div class="bg-zinc-900 border border-zinc-800 p-6 rounded-2xl flex justify-between items-center">
<div class="flex-1">
<h3 class="text-xl font-bold uppercase">${race.name}</h3>
<p class="text-[10px] text-zinc-500">${new Date(race.date).toLocaleString()}</p>
</div>
<div class="flex gap-2">
<button onclick="loadRaceForEdit('${race._id}')" class="text-xs font-bold px-4 py-2 bg-zinc-800 rounded-lg hover:bg-zinc-700 transition-all">EDIT</button>
<button onclick="deleteRace('${race._id}')" class="text-xs font-bold px-4 py-2 border border-red-900 text-red-500 rounded-lg hover:bg-red-900 transition-all">DELETE</button>
</div>
</div>
`;
}
});
if (data.live.length === 0 && data.past.length === 0) {
container.innerHTML = `<p class="text-center py-12 text-zinc-700 font-bold uppercase tracking-widest italic">No events recorded</p>`;
}
});
socket.on('refresh-races', () => socket.emit('get-races'));
function showModal(id) {
document.getElementById(id).classList.remove('hidden');
}
function hideModal(id) {
document.getElementById(id).classList.add('hidden');
}
// Auth Logic
loginSubmitBtn.onclick = () => {
socket.emit('manager-login', document.getElementById('managerCodeInput').value);
};
socket.on('manager-login-success', () => {
setCookie('managerLoggedIn', 'true', 7); // Persist login state for 7 days
managerLoggedIn = true;
hideModal('manageModal');
const urlParams = new URLSearchParams(window.location.search);
const manageId = urlParams.get('manage');
const editId = urlParams.get('edit');
// If they were trying to access a specific room, load it now
if (manageId || editId) {
if (editId) {
editingPastRaceId = editId;
socket.emit('get-race-data', editId);
} else {
currentRoomId = manageId;
socket.emit('get-race-data', manageId);
}
} else {
document.getElementById('listView').classList.add('hidden');
document.getElementById('adminDashboard').classList.remove('hidden');
socket.emit('get-races');
}
});
createBtn.onclick = () => {
const code = "HUSKIES77"; // Internal code since already authed
const name = document.getElementById('raceNameInput').value;
socket.emit('create-room', code, name);
};
document.getElementById('joinBtn').onclick = () => {
const code = document.getElementById('joinCodeInput').value.trim().toUpperCase();
if (code) window.location.href = `/camera.html?room=${code}`;
};
toggleHeatsBtn.onclick = () => {
if (!currentRoomId) return;
isHeatsEnabled = !isHeatsEnabled;
socket.emit('toggle-heats', currentRoomId, isHeatsEnabled);
};
finishHeatBtn.onclick = () => {
if (!currentRoomId) return;
// Stop current race
socket.emit('stop-race', currentRoomId);
// Increment heat after a short delay to ensure stop state is processed
setTimeout(() => {
socket.emit('set-current-heat', currentRoomId, currentHeat + 1);
}, 100);
};
socket.on('heats-toggled', (enabled) => {
isHeatsEnabled = enabled;
toggleHeatsBtn.innerText = enabled ? "DISABLE HEATS" : "ENABLE HEATS";
heatControlBar.classList.toggle('hidden', !enabled);
updateUI();
});
prevHeatBtn.onclick = () => {
if (currentHeat > 1) socket.emit('set-current-heat', currentRoomId, currentHeat - 1);
};
nextHeatBtn.onclick = () => {
socket.emit('set-current-heat', currentRoomId, currentHeat + 1);
};
socket.on('heat-changed', (heatIdx) => {
currentHeat = heatIdx;
currentHeatDisplay.innerText = heatIdx;
prevHeatBtn.disabled = heatIdx <= 1;
clearInterval(timerInterval);
// Prepare UI for new heat
startRaceBtn.classList.remove('hidden');
audioStartBtn.classList.remove('hidden');
stopRaceBtn.classList.add('hidden');
raceClock.innerText = "00:00.0";
updateUI();
});
socket.on('room-created', (roomId, name) => {
currentRoomId = roomId;
document.getElementById('setupView').classList.add('hidden');
document.getElementById('setupView').classList.add('hidden'); // Ensure setupView is hidden
document.getElementById('listView').classList.add('hidden');
document.getElementById('adminDashboard').classList.add('hidden');
hideModal('createRaceModal');
document.getElementById('roomDash').style.display = 'flex';
document.getElementById('codeDisplay').innerText = roomId;
document.getElementById('activeRaceName').innerText = name;
setManagementUrl('manage', roomId); // Update URL on creation
isHeatsEnabled = false;
currentHeat = 1;
heatData = {};
const viewerUrl = `${window.location.origin}/viewer.html?room=${roomId}`;
document.getElementById('viewerCode').innerText = viewerUrl;
document.getElementById('viewerCode').onclick = () => {
navigator.clipboard.writeText(viewerUrl);
alert("Viewer link copied to clipboard!");
};
});
socket.on('error-msg', (msg) => {
alert(msg);
});
socket.on('camera-status', (stat) => {
document.getElementById('status').innerText = 'Camera: Connected';
document.getElementById('status').classList.replace('bg-zinc-800', 'bg-green-600/20');
document.getElementById('status').classList.replace('text-zinc-400', 'text-green-500');
});
socket.on('request-sync', () => {
updateUI();
});
// Race Management
startRaceBtn.onclick = () => {
if (currentRoomId) socket.emit('start-race', currentRoomId);
};
socket.on('race-started', (startTime, heatIdx) => {
if (heatIdx) {
heatData[heatIdx] = { startTime, stopTime: null };
} else {
raceStartTime = startTime;
}
isRaceStopped = false;
raceStopTime = null;
startRaceBtn.classList.add('hidden');
audioStartBtn.classList.add('hidden');
stopRaceBtn.classList.remove('hidden');
endRaceBtn.classList.add('hidden');
manualSplitBtn.classList.remove('hidden');
falseStartBtn.classList.remove('hidden');
if (isHeatsEnabled) finishHeatBtn.classList.remove('hidden');
raceClock.classList.remove('hidden');
clearInterval(timerInterval);
timerInterval = setInterval(() => {
const activeStart = isHeatsEnabled ? heatData[currentHeat]?.startTime : raceStartTime;
if (!activeStart) return;
const diff = Date.now() - activeStart;
raceClock.innerText = formatTime(diff);
}, 100);
});
socket.on('race-stopped', (stopTime, heatIdx) => {
isRaceStopped = true;
if (heatIdx) {
if (heatData[heatIdx]) heatData[heatIdx].stopTime = stopTime;
} else {
raceStopTime = stopTime;
}
clearInterval(timerInterval);
const activeStart = isHeatsEnabled ? heatData[currentHeat]?.startTime : raceStartTime;
const activeStop = isHeatsEnabled ? heatData[currentHeat]?.stopTime : raceStopTime;
if (activeStart && activeStop) raceClock.innerText = formatTime(activeStop - activeStart);
falseStartBtn.classList.add('hidden');
stopRaceBtn.classList.add('hidden');
endRaceBtn.classList.remove('hidden');
finishHeatBtn.classList.add('hidden');
manualSplitBtn.classList.add('hidden');
// Allow starting again (e.g. for next heat or restart)
startRaceBtn.classList.remove('hidden');
audioStartBtn.classList.remove('hidden');
updateUI();
});
socket.on('race-ended-success', () => {
raceStartTime = null;
isRaceStopped = false;
raceStopTime = null;
isHeatsEnabled = false;
finishHeatBtn.classList.add('hidden');
currentHeat = 1;
setManagementUrl(); // Clear management params from URL
heatData = {};
toggleHeatsBtn.innerText = "ENABLE HEATS";
heatControlBar.classList.add('hidden');
clearInterval(timerInterval);
document.getElementById('roomDash').style.display = 'none';
document.getElementById('adminDashboard').classList.remove('hidden');
allSplits = [];
socket.emit('get-races');
});
stopRaceBtn.onclick = () => {
if (currentRoomId) socket.emit('stop-race', currentRoomId);
};
endRaceBtn.onclick = () => {
if (confirm("End race and save final results to database?")) {
socket.emit('end-race', currentRoomId, {
startList,
allSplits, // allSplits now contains images for manager, but server will strip for permanent record
raceStartTime,
raceStopTime,
lapDist: parseFloat(document.getElementById('lapDist').value) || 400,
minSplitTime: parseFloat(document.getElementById('minSplitTimeInput').value) || 5,
isHeatsEnabled,
heatData
});
}
};
saveEditBtn.onclick = () => {
if (editingPastRaceId) {
socket.emit('update-race', {
id: editingPastRaceId,
name: document.getElementById('activeRaceName').innerText || "Updated Race",
startList,
allSplits, // allSplits now contains images for manager, but server will strip for permanent record
raceStartTime,
raceStopTime,
lapDist: parseFloat(document.getElementById('lapDist').value) || 400,
minSplitTime: parseFloat(document.getElementById('minSplitTimeInput').value) || 5,
isHeatsEnabled,
heatData
});
}
};
socket.on('race-updated-success', () => {
alert("Changes saved to database.");
location.reload();
});
window.loadRaceForEdit = (id) => {
editingPastRaceId = id; // Set this flag before emitting
setManagementUrl('edit', id); // Update URL for editing
socket.emit('get-race-data', id);
};
const marksBtn = document.getElementById('marksBtn');
const setBtn = document.getElementById('setBtn');
const falseStartBtn = document.getElementById('falseStartBtn');
const audioTarget = document.getElementById('audioTarget');
const playAudio = (command) => {
if (command === 'marks') {
const msg = new SpeechSynthesisUtterance("runners on your marks");
window.speechSynthesis.speak(msg);
} else if (command === 'set') {
const msg = new SpeechSynthesisUtterance("set");
window.speechSynthesis.speak(msg);
} else if (command === 'start' || command === 'false-start') {
new Audio('start.mp3').play().catch(() => {});
}
};
socket.on('play-audio', (cmd) => playAudio(cmd));
marksBtn.onclick = () => socket.emit('broadcast-audio', { roomId: currentRoomId, command: 'marks', target: audioTarget.value });
setBtn.onclick = () => socket.emit('broadcast-audio', { roomId: currentRoomId, command: 'set', target: audioTarget.value });
audioStartBtn.onclick = () => socket.emit('broadcast-audio', { roomId: currentRoomId, command: 'start', target: audioTarget.value });
falseStartBtn.onclick = () => socket.emit('broadcast-audio', { roomId: currentRoomId, command: 'false-start', target: audioTarget.value });
socket.on('race-false-start', (heatIdx) => {
if (heatIdx) {
delete heatData[heatIdx];
} else {
raceStartTime = null;
}
isRaceStopped = false;
raceStopTime = null;
clearInterval(timerInterval);
raceClock.innerText = "00:00.0";
audioStartBtn.classList.remove('hidden');
startRaceBtn.classList.remove('hidden');
falseStartBtn.classList.add('hidden');
finishHeatBtn.classList.add('hidden');
stopRaceBtn.classList.add('hidden');
manualSplitBtn.classList.add('hidden');
updateUI();
});
socket.on('race-data-loaded', (race) => {
// Determine if we are loading a past race for editing or re-entering a live room
const isEditingPastRace = editingPastRaceId !== null; // editingPastRaceId is set by loadRaceForEdit
// Normalize timestamps to numbers (handles ISO strings from DB)
raceStartTime = race.raceStartTime ? new Date(race.raceStartTime).getTime() : null;
raceStopTime = race.raceStopTime ? new Date(race.raceStopTime).getTime() : null;
allSplits = (race.allSplits || []).map(s => ({ ...s, timestamp: new Date(s.timestamp).getTime() }));
heatData = race.heatData || {};
Object.keys(heatData).forEach(h => {
if (heatData[h].startTime) heatData[h].startTime = new Date(heatData[h].startTime).getTime();
if (heatData[h].stopTime) heatData[h].stopTime = new Date(heatData[h].stopTime).getTime();
});
if (isEditingPastRace) {
// Existing logic for editing past races
startList = race.startList || [];
isHeatsEnabled = race.isHeatsEnabled || false;
currentHeat = 1; // Reset to 1 for editing context
toggleHeatsBtn.innerText = isHeatsEnabled ? "DISABLE HEATS" : "ENABLE HEATS";
heatControlBar.classList.toggle('hidden', !isHeatsEnabled);
currentHeatDisplay.innerText = currentHeat;
document.getElementById('lapDist').value = race.lapDist || 400;
document.getElementById('minSplitTimeInput').value = race.minSplitTime !== undefined ? race.minSplitTime : 5;
nameInput.value = startList.join('\n');
document.getElementById('activeRaceName').innerText = race.name;
document.getElementById('adminDashboard').classList.add('hidden');
document.getElementById('roomDash').style.display = 'flex';
document.getElementById('codeDisplay').innerText = "EDIT MODE";
// Adjust UI for Edit Mode
startRaceBtn.classList.add('hidden');
stopRaceBtn.classList.add('hidden');
endRaceBtn.classList.add('hidden');
saveEditBtn.classList.remove('hidden'); // Only visible in edit mode
manualSplitBtn.classList.remove('hidden');
raceClock.classList.remove('hidden');
const activeStart = isHeatsEnabled ? heatData[currentHeat]?.startTime : raceStartTime;
const activeStop = isHeatsEnabled ? heatData[currentHeat]?.stopTime : raceStopTime;
if (activeStart && activeStop) raceClock.innerText = formatTime(activeStop - activeStart);
} else {
// Logic for re-entering a live room (currentRoomId would be set from localStorage)
currentRoomId = race.roomId || race._id;
startList = race.startList || [];
isHeatsEnabled = race.isHeatsEnabled || false;
currentHeat = race.currentHeat || 1; // Use the actual current heat from the server
toggleHeatsBtn.innerText = isHeatsEnabled ? "DISABLE HEATS" : "ENABLE HEATS";
heatControlBar.classList.toggle('hidden', !isHeatsEnabled);
currentHeatDisplay.innerText = currentHeat;
document.getElementById('lapDist').value = race.lapDist || 400;
document.getElementById('minSplitTimeInput').value = race.minSplitTime !== undefined ? race.minSplitTime : 5;
nameInput.value = startList.join('\n');
document.getElementById('activeRaceName').innerText = race.name;
document.getElementById('setupView').classList.add('hidden');
document.getElementById('listView').classList.add('hidden');
document.getElementById('adminDashboard').classList.add('hidden');
document.getElementById('roomDash').style.display = 'flex';
document.getElementById('codeDisplay').innerText = currentRoomId;
const viewerUrl = `${window.location.origin}/viewer.html?room=${currentRoomId}`;
document.getElementById('viewerCode').innerText = viewerUrl;
document.getElementById('viewerCode').onclick = () => {
navigator.clipboard.writeText(viewerUrl);
alert("Viewer link copied to clipboard!");
};
// Adjust UI for Live Room
saveEditBtn.classList.add('hidden'); // Not in edit mode
manualSplitBtn.classList.remove('hidden');
raceClock.classList.remove('hidden');
// Set race control buttons based on race state
if (raceStartTime && !raceStopTime) { // Race is active
isRaceStopped = false;
startRaceBtn.classList.add('hidden');
audioStartBtn.classList.add('hidden');
stopRaceBtn.classList.remove('hidden');
endRaceBtn.classList.add('hidden');
falseStartBtn.classList.remove('hidden');
if (isHeatsEnabled) finishHeatBtn.classList.remove('hidden');
clearInterval(timerInterval);
timerInterval = setInterval(() => {
const activeStart = isHeatsEnabled ? heatData[currentHeat]?.startTime : raceStartTime;
if (!activeStart) return;
const diff = Date.now() - activeStart;
raceClock.innerText = formatTime(diff);
}, 100);
} else if (raceStartTime && raceStopTime) { // Race is stopped
isRaceStopped = true;
startRaceBtn.classList.remove('hidden');
audioStartBtn.classList.remove('hidden');
stopRaceBtn.classList.add('hidden');
endRaceBtn.classList.remove('hidden');
falseStartBtn.classList.add('hidden');
finishHeatBtn.classList.add('hidden');
manualSplitBtn.classList.add('hidden'); // Manual split only during active race
clearInterval(timerInterval);
const activeStart = isHeatsEnabled ? heatData[currentHeat]?.startTime : raceStartTime;
const activeStop = isHeatsEnabled ? heatData[currentHeat]?.stopTime : raceStopTime;
if (activeStart && activeStop) raceClock.innerText = formatTime(activeStop - activeStart);
} else { // Race not started yet
isRaceStopped = false;
startRaceBtn.classList.remove('hidden');
audioStartBtn.classList.remove('hidden');
stopRaceBtn.classList.add('hidden');
endRaceBtn.classList.add('hidden');
falseStartBtn.classList.add('hidden');
finishHeatBtn.classList.add('hidden');
manualSplitBtn.classList.add('hidden');
raceClock.innerText = "00:00.0";
}
}
updateUI();
});
manualSplitBtn.onclick = () => {
if (!raceStartTime) return;
const split = {
id: Date.now() + Math.random(),
timestamp: Date.now(),
image: null,
runnerNames: [],
multiMode: false,
heatIndex: isHeatsEnabled ? currentHeat : null
};
allSplits.unshift(split);
updateUI();
};
updateListBtn.onclick = () => {
startList = nameInput.value.split('\n').map(n => n.trim()).filter(n => n);
const minSplit = parseFloat(document.getElementById('minSplitTimeInput').value) || 0;
if (currentRoomId) {
socket.emit('set-min-split-time', currentRoomId, minSplit);
}
updateUI();
};
socket.on('new-split', (data) => {
const split = {
id: data.splitId, // Use server-generated splitId
timestamp: data.timestamp,
image: data.image,
runnerNames: [],
multiMode: false,
heatIndex: data.heatIndex
};
allSplits.unshift(split);
updateUI();
});
function updateUI() {
// Render Feed
resultsDiv.innerHTML = '';
let lastHeat = null;
allSplits.forEach(split => {
if (isHeatsEnabled && split.heatIndex !== lastHeat) {
lastHeat = split.heatIndex;
const divider = document.createElement('div');
divider.className = 'col-span-full py-4 flex items-center gap-4 mt-6';
divider.innerHTML = `
<div class="h-[1px] flex-1 bg-zinc-800"></div>
<h4 class="text-xl font-black text-red-600 uppercase italic">Heat ${split.heatIndex || 1}</h4>
<div class="h-[1px] flex-1 bg-zinc-800"></div>
`;
resultsDiv.appendChild(divider);
}
const card = document.createElement('div');
card.className = 'bg-black border border-zinc-800 rounded-xl overflow-hidden';
const activeStart = isHeatsEnabled ? (heatData[split.heatIndex]?.startTime) : raceStartTime;
const relTime = activeStart ? formatTime(split.timestamp - activeStart) : new Date(split.timestamp).toLocaleTimeString();
let assignmentUI = '';
if (!split.multiMode) {
assignmentUI = `
<select onchange="handleSplitSelect(${split.id}, this.value)" class="w-full bg-zinc-900 border border-zinc-700 rounded-lg py-2 px-2 text-xs focus:outline-none">
<option value="">Assign Runner...</option>
${startList.map(name => `<option value="${name}" ${split.runnerNames.length === 1 && split.runnerNames[0] === name ? 'selected' : ''}>${name}</option>`).join('')}
<option value="__MULTI__" class="text-red-600 font-bold">Multiple Runners...</option>
</select>
`;
} else {
assignmentUI = `
<div class="flex justify-between items-center mb-1"><span class="text-[8px] text-zinc-500 uppercase font-bold">Multi-Select</span><button onclick="setSplitMode(${split.id}, false)" class="text-[8px] text-red-500 font-bold uppercase hover:underline">Switch to Single</button></div>
<div class="space-y-1 max-h-24 overflow-y-auto border border-zinc-800 rounded-lg p-2 bg-zinc-900/50">
${startList.map(name => `
<label class="flex items-center gap-2 cursor-pointer hover:bg-zinc-800 p-1 rounded transition-colors text-[10px]">
<input type="checkbox" onchange="toggleAssignment(${split.id}, '${name.replace(/'/g, "\\'")}')" ${split.runnerNames.includes(name) ? 'checked' : ''} class="accent-red-600">
<span class="${split.runnerNames.includes(name) ? 'text-white font-bold' : 'text-zinc-500'}">${name}</span>
</label>
`).join('')}
</div>
`;
}
card.innerHTML = `
<img src="${split.image || MANUAL_IMG}" class="w-full h-32 object-cover opacity-80">
<div class="p-3">
<div class="flex justify-between items-center mb-3">
<span class="font-mono text-lg text-red-600">${relTime}</span>
<button onclick="deleteSplit(${split.id})" class="text-zinc-600 hover:text-red-500 font-bold text-xs uppercase transition-colors">Delete</button>
</div>
${assignmentUI}
</div>
`;
resultsDiv.appendChild(card);
});
// Calculate Leaderboard
calculatedLeaderboard = [];
const dist = parseFloat(document.getElementById('lapDist').value) || 400;
const runners = {};
startList.forEach(name => runners[name] = { laps: [], total: 0, splitDetails: [] });
let eventTotalLaps = 0;
const runnerLastTs = {};
// Calculate stats based on assignments (sorted chronologically)
[...allSplits].sort((a, b) => a.timestamp - b.timestamp).forEach(split => {
const hIdx = split.heatIndex || 1;
const hStart = isHeatsEnabled ? heatData[hIdx]?.startTime : raceStartTime;
if (!hStart) return;
split.runnerNames.forEach(name => {
if (runners[name]) {
const r = runners[name];
if (!runnerLastTs[name]) runnerLastTs[name] = {};
const prevTs = runnerLastTs[name][hIdx] || hStart;
const lapTime = split.timestamp - prevTs;
if (lapTime >= 0) {
r.laps.push(lapTime);
eventTotalLaps++;
r.total += lapTime;
runnerLastTs[name][hIdx] = split.timestamp;
r.splitDetails.push({
...split,
lapTime,
lapIndex: r.laps.length
});
}
}
});
});
document.getElementById('statLaps').innerText = eventTotalLaps;
document.getElementById('statMeters').innerHTML = `${Math.round(eventTotalLaps * dist)}<span class="text-xs ml-1 text-zinc-500 font-bold uppercase">m</span>`;
document.getElementById('statMiles').innerText = (eventTotalLaps * dist / 1609.34).toFixed(2);
leaderboardDiv.innerHTML = startList.map(name => {
const r = runners[name];
const lapCount = r.laps.length;
const avgLap = lapCount > 0 ? r.total / lapCount : 0;
const milePace = avgLap > 0 ? (avgLap / 1000 / dist) * 1609.34 : 0; // Pace in seconds per mile
calculatedLeaderboard.push({
name,
total: r.total,
laps: lapCount,
pace: formatPace(milePace)
});
return `
<div class="bg-black p-4 rounded-xl border border-zinc-800">
<div class="flex justify-between items-start mb-2">
<span class="font-bold text-lg">${name}</span>
<span class="bg-red-600/10 text-red-500 px-2 py-1 rounded text-[10px] font-bold uppercase">${lapCount} Laps</span>
</div>
<div class="grid grid-cols-2 gap-2 text-[10px] uppercase font-bold text-zinc-500 mb-4">
<div>Total: <span class="text-white font-mono">${formatTime(r.total)}</span></div>
<div>Pace: <span class="text-white font-mono">${formatPace(milePace)}</span></div>
</div>
<!-- Individual Splits for this runner -->
<div class="space-y-1.5 mt-2 border-t border-zinc-800 pt-3">
${r.splitDetails.slice().reverse().map(sd => `
<div class="flex items-center justify-between text-[10px] bg-zinc-800/40 p-1.5 rounded-lg border border-zinc-700/30">
<div class="flex items-center gap-2">
<img src="${sd.image || MANUAL_IMG}" class="w-6 h-6 rounded object-cover border border-zinc-700">
<span class="text-zinc-400 font-bold">LAP ${sd.lapIndex}</span>
</div>
<span class="font-mono text-white">${formatTime(sd.lapTime)}</span>
<span class="font-mono text-zinc-600">${formatTime(sd.timestamp - (isHeatsEnabled ? (heatData[sd.heatIndex]?.startTime || 0) : (raceStartTime || 0)))}</span>
</div>
`).join('')}
</div>
</div>
`;
}).join('');
// Sync to viewers
if (currentRoomId) {
socket.emit('sync-to-viewers', {
roomId: currentRoomId,
name: document.getElementById('activeRaceName').innerText,
startList,
allSplits, // Send full allSplits to server, server will strip images for viewers
raceStartTime,
raceStopTime,
isStopped: isRaceStopped,
lapDist: parseFloat(document.getElementById('lapDist').value) || 400,
isHeatsEnabled,