-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbc.html
More file actions
751 lines (645 loc) · 22.9 KB
/
bc.html
File metadata and controls
751 lines (645 loc) · 22.9 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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>좌석 배치 + 예약</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root{
--cell: 36px;
--gap: 4px;
--ink: #333;
--accent: #667eea;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
color: var(--ink);
}
/* 헤더 */
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 40px;
background: white;
margin-bottom: 30px;
border-radius: 15px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
max-width: 1280px;
margin: 0 auto 30px auto;
}
.logo {
font-size: 28px;
font-weight: 600;
background: linear-gradient(135deg, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.school-name {
font-size: 18px;
color: #666;
font-weight: 500;
}
.user-info {
display: flex;
align-items: center;
gap: 15px;
}
.user-name {
font-size: 15px;
color: #667eea;
font-weight: 600;
}
.my-seat-badge {
padding: 8px 16px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 20px;
font-size: 13px;
font-weight: 600;
}
.home-btn {
padding: 10px 20px;
background: white;
border: 2px solid #667eea;
border-radius: 10px;
color: #667eea;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-block;
}
.home-btn:hover {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-color: transparent;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
/* 메인 컨테이너 */
.main-container {
max-width: 1280px;
margin: 0 auto;
background: white;
border-radius: 15px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.page-title {
font-size: 24px;
font-weight: 600;
color: #333;
margin-bottom: 25px;
}
.info-message {
padding: 15px 20px;
background: #f0f7ff;
border-left: 4px solid #667eea;
border-radius: 8px;
margin-bottom: 25px;
font-size: 14px;
color: #555;
}
/* 홀 레이아웃 */
.hall {
display: grid;
grid-template-columns: auto 32px auto 32px auto;
align-items: start;
gap: 0;
margin: 0 auto;
width: fit-content;
}
.zone {
display: grid;
gap: var(--gap);
}
.zone-left {
grid-template-columns: repeat(8, var(--cell));
width: calc(var(--cell)*8 + var(--gap)*7);
}
.zone-mid {
grid-template-columns: repeat(3, var(--cell));
width: calc(var(--cell)*3 + var(--gap)*2);
}
.zone-right {
grid-template-columns: repeat(10, var(--cell));
width: calc(var(--cell)*10 + var(--gap)*9);
}
/* 좌석/박스 기본 */
.seat, .box {
border: 2px solid #d0d0d0;
min-height: var(--cell);
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
font-weight: 500;
user-select: none;
border-radius: 6px;
background: #ffffff;
color: #666;
transition: all 0.3s ease;
}
.seat {
cursor: pointer;
}
.seat:hover:not(.reserved):not(.my-seat) {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
border-color: #667eea;
}
.seat.reserved {
background: #e0e0e0;
color: #999;
border-color: #c0c0c0;
cursor: not-allowed;
}
.seat.my-seat {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: #fff;
font-weight: 600;
border-color: #667eea;
cursor: pointer;
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
/* 교사 영역 */
.teacher-area {
grid-column: 1 / -1;
grid-row: span 2;
min-height: calc(var(--cell)*2 + var(--gap)*1);
background: #f0f0f0;
border-color: #c0c0c0;
}
.span-2 {
grid-column: span 2;
background: #f0f0f0;
border-color: #c0c0c0;
}
.box {
background: #f0f0f0;
border-color: #c0c0c0;
}
/* 모달 */
.backdrop {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
display: none;
align-items: center;
justify-content: center;
z-index: 1000;
backdrop-filter: blur(4px);
}
.backdrop[aria-hidden="false"] {
display: flex;
}
.modal {
position: relative;
background: white;
width: min(92vw, 420px);
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
.x {
position: absolute;
right: 15px;
top: 15px;
width: 32px;
height: 32px;
border: none;
border-radius: 50%;
background: #f5f5f5;
color: #666;
cursor: pointer;
font-size: 20px;
display: grid;
place-items: center;
transition: all 0.3s ease;
z-index: 10;
}
.x:hover {
background: #e0e0e0;
transform: rotate(90deg);
}
.modal-head {
padding: 25px 30px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
font-size: 20px;
font-weight: 600;
}
.modal-body {
padding: 25px 30px;
display: grid;
gap: 18px;
}
.modal-body p {
font-size: 15px;
color: #666;
line-height: 1.5;
}
.btn {
height: 44px;
border: none;
border-radius: 8px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
font-size: 15px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
.btn:active {
transform: translateY(0);
}
.btn-cancel {
background: #dc3545;
}
.btn-cancel:hover {
box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4);
}
.loading {
text-align: center;
padding: 40px;
color: #667eea;
font-size: 16px;
}
@media (max-width: 768px) {
.header {
flex-direction: column;
gap: 15px;
text-align: center;
}
.main-container {
padding: 20px;
}
}
</style>
</head>
<body>
<!-- 헤더 -->
<div class="header">
<div class="logo">AllOfUs</div>
<div class="school-name">경희고등학교</div>
<div class="user-info">
<a href="index.html" class="home-btn">🏠 홈으로</a>
<span class="my-seat-badge" id="mySeatBadge" style="display: none;"></span>
</div>
</div>
<!-- 메인 컨테이너 -->
<div class="main-container">
<h2 class="page-title">제 2청운재 좌석 배치</h2>
<div class="info-message" id="infoMessage">
로그인 후 좌석을 예약할 수 있습니다.
</div>
<div id="loadingArea" class="loading">좌석 정보를 불러오는 중...</div>
<div class="hall" id="hallArea" style="display: none;">
<!-- 왼쪽 블록 (8열) -->
<div class="zone zone-left">
<!-- 1행 -->
<div class="seat" data-seat="1">1</div><div class="seat" data-seat="2">2</div><div class="seat" data-seat="3">3</div><div class="seat" data-seat="4">4</div>
<div class="seat" data-seat="5">5</div><div class="seat" data-seat="6">6</div><div class="seat" data-seat="7">7</div><div class="seat" data-seat="8">8</div>
<!-- 2행 (역순) -->
<div class="seat" data-seat="42">42</div><div class="seat" data-seat="41">41</div><div class="seat" data-seat="40">40</div><div class="seat" data-seat="39">39</div>
<div class="seat" data-seat="38">38</div><div class="seat" data-seat="37">37</div><div class="seat" data-seat="36">36</div><div class="seat" data-seat="35">35</div>
<!-- 3행 -->
<div class="seat" data-seat="43">43</div><div class="seat" data-seat="44">44</div><div class="seat" data-seat="45">45</div><div class="seat" data-seat="46">46</div>
<div class="seat" data-seat="47">47</div><div class="seat" data-seat="48">48</div><div class="seat" data-seat="49">49</div><div class="seat" data-seat="50">50</div>
<!-- 4행 (역순) -->
<div class="seat" data-seat="81">81</div><div class="seat" data-seat="80">80</div><div class="seat" data-seat="79">79</div><div class="seat" data-seat="78">78</div>
<div class="seat" data-seat="77">77</div><div class="seat" data-seat="76">76</div><div class="seat" data-seat="75">75</div><div class="seat" data-seat="74">74</div>
<!-- 5행 -->
<div class="seat" data-seat="82">82</div><div class="seat" data-seat="83">83</div><div class="seat" data-seat="84">84</div><div class="seat" data-seat="85">85</div>
<div class="seat" data-seat="86">86</div><div class="seat" data-seat="87">87</div><div class="seat" data-seat="88">88</div><div class="seat" data-seat="89">89</div>
</div>
<!-- 가운데 통로 -->
<div></div>
<!-- 가운데 블록 (3열) -->
<div class="zone zone-mid">
<!-- 1행 -->
<div class="seat" data-seat="9">9</div><div class="seat" data-seat="10">10</div><div class="seat" data-seat="11">11</div>
<!-- 2행 (역순) -->
<div class="seat" data-seat="34">34</div><div class="seat" data-seat="33">33</div><div class="seat" data-seat="32">32</div>
<!-- 3행 -->
<div class="seat" data-seat="51">51</div><div class="seat" data-seat="52">52</div><div class="seat" data-seat="53">53</div>
<!-- 교사 영역 -->
<div class="box teacher-area"></div>
</div>
<!-- 오른쪽 통로 -->
<div></div>
<!-- 오른쪽 블록 (10열) -->
<div class="zone zone-right">
<!-- 1행 -->
<div class="seat" data-seat="12">12</div><div class="seat" data-seat="13">13</div><div class="seat" data-seat="14">14</div><div class="seat" data-seat="15">15</div>
<div class="seat" data-seat="16">16</div><div class="seat" data-seat="17">17</div><div class="seat" data-seat="18">18</div><div class="seat" data-seat="19">19</div>
<div class="seat" data-seat="20">20</div><div class="seat" data-seat="21">21</div>
<!-- 2행 (역순) -->
<div class="seat" data-seat="31">31</div><div class="seat" data-seat="30">30</div><div class="seat" data-seat="29">29</div><div class="seat" data-seat="28">28</div>
<div class="seat" data-seat="27">27</div><div class="seat" data-seat="26">26</div><div class="seat" data-seat="25">25</div><div class="seat" data-seat="24">24</div>
<div class="seat" data-seat="23">23</div><div class="seat" data-seat="22">22</div>
<!-- 3행 -->
<div class="seat" data-seat="54">54</div><div class="seat" data-seat="55">55</div><div class="seat" data-seat="56">56</div><div class="seat" data-seat="57">57</div>
<div class="seat" data-seat="58">58</div><div class="seat" data-seat="59">59</div><div class="seat" data-seat="60">60</div><div class="seat" data-seat="61">61</div>
<div class="seat" data-seat="62">62</div><div class="seat" data-seat="63">63</div>
<!-- 4행 (역순) -->
<div class="seat" data-seat="73">73</div><div class="seat" data-seat="72">72</div><div class="seat" data-seat="71">71</div><div class="seat" data-seat="70">70</div>
<div class="seat" data-seat="69">69</div><div class="seat" data-seat="68">68</div><div class="seat" data-seat="67">67</div><div class="seat" data-seat="66">66</div>
<div class="seat" data-seat="65">65</div><div class="seat" data-seat="64">64</div>
<!-- 5행 -->
<div class="seat" data-seat="90">90</div><div class="seat" data-seat="91">91</div><div class="seat" data-seat="92">92</div><div class="seat" data-seat="93">93</div>
<div class="seat" data-seat="94">94</div><div class="seat" data-seat="95">95</div><div class="seat" data-seat="96">96</div><div class="seat" data-seat="97">97</div>
<div class="seat" data-seat="98">98</div><div class="seat" data-seat="99">99</div>
</div>
</div>
</div>
<!-- 예약 모달 -->
<div class="backdrop" id="backdrop" aria-hidden="true">
<div class="modal" role="dialog" aria-modal="true">
<button class="x" id="closeBtn" aria-label="닫기">✕</button>
<div class="modal-head" id="modalTitle">좌석 예약</div>
<div class="modal-body">
<p id="modalInfo">선택한 좌석을 예약합니다.</p>
<button class="btn" id="reserveBtn">예약하기</button>
</div>
</div>
</div>
<!-- 취소 모달 -->
<div class="backdrop" id="cancelBackdrop" aria-hidden="true">
<div class="modal" role="dialog" aria-modal="true">
<button class="x" id="closeCancelBtn" aria-label="닫기">✕</button>
<div class="modal-head">예약 취소</div>
<div class="modal-body">
<p id="cancelInfo">좌석 예약을 취소하시겠습니까?</p>
<button class="btn btn-cancel" id="cancelBtn">예약 취소하기</button>
</div>
</div>
</div>
<script type="module">
import { initializeApp, getApps } from "https://www.gstatic.com/firebasejs/9.0.0/firebase-app.js";
import { getAuth, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/9.0.0/firebase-auth.js";
import { getDatabase, ref, get, set, remove, onValue } from "https://www.gstatic.com/firebasejs/9.0.0/firebase-database.js";
// Firebase 설정
const firebaseConfig = {
apiKey: "AIzaSyD1HNrS-TcAUvmJvWJYowzIPbyIC1_sMjg",
authDomain: "hack-7974a.firebaseapp.com",
projectId: "hack-7974a",
storageBucket: "hack-7974a.firebasestorage.app",
messagingSenderId: "831807416935",
appId: "1:831807416935:web:461949fd6baa1510e042c2",
measurementId: "G-DKMJZBKLG2"
};
const app = getApps().length ? getApps()[0] : initializeApp(firebaseConfig);
const auth = getAuth(app);
const database = getDatabase(app);
let currentUser = null;
let currentSeatEl = null;
let allReservations = {};
// 오늘 날짜를 YYYY-MM-DD 형식으로 반환
function getTodayKey() {
const today = new Date();
return today.toISOString().split('T')[0];
}
// 모달 요소
const backdrop = document.getElementById('backdrop');
const closeBtn = document.getElementById('closeBtn');
const reserveBtn = document.getElementById('reserveBtn');
const modalTitle = document.getElementById('modalTitle');
const modalInfo = document.getElementById('modalInfo');
const cancelBackdrop = document.getElementById('cancelBackdrop');
const closeCancelBtn = document.getElementById('closeCancelBtn');
const cancelBtn = document.getElementById('cancelBtn');
const cancelInfo = document.getElementById('cancelInfo');
// 예약 모달 열기/닫기
function openModalFor(seatEl) {
currentSeatEl = seatEl;
const n = seatEl.dataset.seat;
modalTitle.textContent = `좌석 ${n} 예약`;
modalInfo.textContent = `좌석 ${n}을(를) 예약하시겠습니까?`;
backdrop.setAttribute('aria-hidden', 'false');
}
function closeModal() {
backdrop.setAttribute('aria-hidden', 'true');
currentSeatEl = null;
}
// 취소 모달 열기/닫기
function openCancelModal(seatNumber) {
cancelInfo.textContent = `좌석 ${seatNumber} 예약을 취소하시겠습니까?`;
cancelBackdrop.setAttribute('aria-hidden', 'false');
}
function closeCancelModal() {
cancelBackdrop.setAttribute('aria-hidden', 'true');
}
// 모달 닫기 버튼
closeBtn.addEventListener('click', closeModal);
closeCancelBtn.addEventListener('click', closeCancelModal);
// 모든 좌석 예약 정보 로드
async function loadAllReservations() {
const todayKey = getTodayKey();
const reservationsRef = ref(database, `reservations/${todayKey}`);
return new Promise((resolve) => {
onValue(reservationsRef, (snapshot) => {
allReservations = {};
if (snapshot.exists()) {
const data = snapshot.val();
// 사용자별 예약 정보를 좌석별로 재구성
Object.keys(data).forEach(userId => {
const seatNumber = data[userId].seatNumber;
allReservations[seatNumber] = userId;
});
}
updateSeatsUI();
resolve();
});
});
}
// 사용자의 예약 정보 로드
async function loadUserReservation(userId) {
const todayKey = getTodayKey();
const userReservationRef = ref(database, `reservations/${todayKey}/${userId}`);
const snapshot = await get(userReservationRef);
if (snapshot.exists()) {
return snapshot.val();
}
return null;
}
// UI 업데이트
function updateSeatsUI() {
const seats = document.querySelectorAll('.seat');
seats.forEach(seat => {
const seatNumber = seat.dataset.seat;
seat.classList.remove('reserved', 'my-seat');
if (allReservations[seatNumber]) {
if (currentUser && allReservations[seatNumber] === currentUser.uid) {
seat.classList.add('my-seat');
} else {
seat.classList.add('reserved');
}
}
});
}
// 좌석 예약
async function reserveSeat(seatNumber) {
if (!currentUser) {
alert('로그인이 필요합니다.');
return;
}
const todayKey = getTodayKey();
// 이미 예약이 있는지 확인
const userReservation = await loadUserReservation(currentUser.uid);
if (userReservation) {
alert('이미 좌석을 예약하셨습니다. 기존 예약을 취소하고 다시 시도해주세요.');
closeModal();
return;
}
// 해당 좌석이 이미 예약되었는지 확인
if (allReservations[seatNumber]) {
alert('이미 예약된 좌석입니다.');
closeModal();
return;
}
try {
// 예약 정보 저장
const reservationRef = ref(database, `reservations/${todayKey}/${currentUser.uid}`);
await set(reservationRef, {
seatNumber: seatNumber,
timestamp: Date.now(),
date: todayKey
});
alert('예약되었습니다.');
closeModal();
await updateUserInfo();
} catch (error) {
console.error('예약 실패:', error);
alert('예약에 실패했습니다. 다시 시도해주세요.');
}
}
// 예약 취소
async function cancelReservation() {
if (!currentUser) return;
const todayKey = getTodayKey();
const userReservation = await loadUserReservation(currentUser.uid);
if (!userReservation) {
alert('예약 정보가 없습니다.');
return;
}
try {
const reservationRef = ref(database, `reservations/${todayKey}/${currentUser.uid}`);
await remove(reservationRef);
alert('예약이 취소되었습니다.');
closeCancelModal();
await updateUserInfo();
} catch (error) {
console.error('취소 실패:', error);
alert('취소에 실패했습니다. 다시 시도해주세요.');
}
}
// 사용자 정보 업데이트
async function updateUserInfo() {
const userNameEl = document.getElementById('userName');
const mySeatBadge = document.getElementById('mySeatBadge');
const infoMessage = document.getElementById('infoMessage');
if (!currentUser) {
userNameEl.textContent = '로그인 필요';
mySeatBadge.style.display = 'none';
infoMessage.textContent = '로그인 후 좌석을 예약할 수 있습니다.';
return;
}
// 예약 정보 확인
const userReservation = await loadUserReservation(currentUser.uid);
if (userReservation) {
mySeatBadge.textContent = `내 좌석: ${userReservation.seatNumber}번`;
mySeatBadge.style.display = 'inline-block';
infoMessage.textContent = `${userReservation.seatNumber}번 좌석을 예약하셨습니다. 좌석을 클릭하면 예약을 취소할 수 있습니다.`;
} else {
mySeatBadge.style.display = 'none';
infoMessage.textContent = '원하는 좌석을 클릭하여 예약하세요. (1인 1좌석만 예약 가능)';
}
}
// 좌석 클릭 이벤트
document.querySelectorAll('.seat').forEach(seat => {
seat.addEventListener('click', async () => {
if (!currentUser) {
alert('로그인이 필요합니다.');
window.location.href = 'login.html';
return;
}
const seatNumber = seat.dataset.seat;
// 내 좌석인 경우 취소 모달
if (seat.classList.contains('my-seat')) {
openCancelModal(seatNumber);
return;
}
// 다른 사람이 예약한 좌석
if (seat.classList.contains('reserved')) {
alert('이미 예약된 좌석입니다.');
return;
}
// 빈 좌석 - 예약 확인
const userReservation = await loadUserReservation(currentUser.uid);
if (userReservation) {
alert(`이미 ${userReservation.seatNumber}번 좌석을 예약하셨습니다. 기존 예약을 취소하고 다시 시도해주세요.`);
return;
}
openModalFor(seat);
});
});
// 예약 버튼
reserveBtn.addEventListener('click', () => {
if (!currentSeatEl) return;
const seatNumber = currentSeatEl.dataset.seat;
reserveSeat(seatNumber);
});
// 취소 버튼
cancelBtn.addEventListener('click', cancelReservation);
// 인증 상태 감지
onAuthStateChanged(auth, async (user) => {
currentUser = user;
if (user) {
console.log('로그인 상태:', user.email);
document.getElementById('loadingArea').style.display = 'none';
document.getElementById('hallArea').style.display = 'grid';
await loadAllReservations();
await updateUserInfo();
} else {
console.log('로그아웃 상태 - index.html로 리다이렉트');
// 로그인하지 않은 경우 홈으로 이동
window.location.href = 'index.html';
}
});
// 매일 자정에 예약 초기화 확인
function checkAndResetReservations() {
const lastCheckDate = localStorage.getItem('lastCheckDate');
const todayKey = getTodayKey();
if (lastCheckDate !== todayKey) {
// 날짜가 바뀌었으면 로컬 저장소 업데이트
localStorage.setItem('lastCheckDate', todayKey);
console.log('새로운 날짜: 예약 정보가 자동으로 초기화됩니다.');
}
}
// 페이지 로드 시 날짜 확인
checkAndResetReservations();
// 1분마다 날짜 변경 확인
setInterval(checkAndResetReservations, 60000);
</script>
</body>
</html>