Spaces:
Running

File size: 38,912 Bytes
9316ab6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Meal Order System</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .fade-in {
            animation: fadeIn 0.3s ease-in-out;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .meal-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
        }
        
        .tab-active {
            border-bottom: 3px solid #3b82f6;
            color: #3b82f6;
            font-weight: 600;
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8 max-w-6xl">
        <!-- Header -->
        <header class="mb-8 text-center">
            <h1 class="text-4xl font-bold text-blue-600 mb-2">Meal Order System</h1>
            <p class="text-gray-600">Order your favorite meals with ease</p>
        </header>

        <!-- Main Content -->
        <div class="bg-white rounded-xl shadow-lg overflow-hidden">
            <!-- Tabs Navigation -->
            <div class="flex border-b border-gray-200">
                <button onclick="switchTab('order')" class="tab-button flex-1 py-4 px-6 text-center font-medium text-gray-500 hover:text-blue-500 focus:outline-none" id="order-tab">
                    <i class="fas fa-utensils mr-2"></i>Order
                </button>
                <button onclick="switchTab('query')" class="tab-button flex-1 py-4 px-6 text-center font-medium text-gray-500 hover:text-blue-500 focus:outline-none" id="query-tab">
                    <i class="fas fa-search mr-2"></i>Query Orders
                </button>
                <button onclick="switchTab('manage')" class="tab-button flex-1 py-4 px-6 text-center font-medium text-gray-500 hover:text-blue-500 focus:outline-none" id="manage-tab">
                    <i class="fas fa-trash-alt mr-2"></i>Delete Orders
                </button>
            </div>

            <!-- Order Tab Content -->
            <div id="order-content" class="p-6 fade-in">
                <h2 class="text-2xl font-semibold mb-6 text-gray-800">Place Your Order</h2>
                
                <!-- Meal Type Selection -->
                <div class="mb-8">
                    <h3 class="text-lg font-medium text-gray-700 mb-4">Select Meal Type</h3>
                    <div class="grid grid-cols-2 md:grid-cols-4 gap-4">
                        <button onclick="selectMealType('breakfast')" class="meal-type-btn py-3 px-4 rounded-lg bg-blue-50 text-blue-600 border border-blue-200 hover:bg-blue-100 transition flex items-center justify-center">
                            <i class="fas fa-sun mr-2"></i> Breakfast
                        </button>
                        <button onclick="selectMealType('lunch')" class="meal-type-btn py-3 px-4 rounded-lg bg-green-50 text-green-600 border border-green-200 hover:bg-green-100 transition flex items-center justify-center">
                            <i class="fas fa-utensils mr-2"></i> Lunch
                        </button>
                        <button onclick="selectMealType('dinner')" class="meal-type-btn py-3 px-4 rounded-lg bg-purple-50 text-purple-600 border border-purple-200 hover:bg-purple-100 transition flex items-center justify-center">
                            <i class="fas fa-moon mr-2"></i> Dinner
                        </button>
                        <button onclick="selectMealType('supply')" class="meal-type-btn py-3 px-4 rounded-lg bg-yellow-50 text-yellow-600 border border-yellow-200 hover:bg-yellow-100 transition flex items-center justify-center">
                            <i class="fas fa-box-open mr-2"></i> Supply
                        </button>
                    </div>
                </div>
                
                <!-- Meal Selection -->
                <div id="meal-selection" class="mb-8">
                    <h3 class="text-lg font-medium text-gray-700 mb-4">Available Meals</h3>
                    <div id="meal-cards" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                        <!-- Meals will be loaded here dynamically -->
                    </div>
                </div>
                
                <!-- Order Form -->
                <div class="bg-gray-50 p-6 rounded-lg">
                    <h3 class="text-lg font-medium text-gray-700 mb-4">Your Order Details</h3>
                    <form id="order-form" class="space-y-4">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <label for="name" class="block text-sm font-medium text-gray-700 mb-1">Name</label>
                                <input type="text" id="name" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <label for="table" class="block text-sm font-medium text-gray-700 mb-1">Table Number</label>
                                <input type="text" id="table" required class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                        </div>
                        
                        <div>
                            <label for="special-requests" class="block text-sm font-medium text-gray-700 mb-1">Special Requests</label>
                            <textarea id="special-requests" rows="2" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"></textarea>
                        </div>
                        
                        <div id="selected-items" class="border border-gray-200 rounded-lg p-4">
                            <h4 class="text-sm font-medium text-gray-700 mb-2">Selected Items</h4>
                            <div id="order-items" class="space-y-2">
                                <p class="text-gray-500 text-sm">No items selected yet</p>
                            </div>
                            <div id="order-total" class="mt-3 pt-3 border-t border-gray-200 text-right font-medium text-gray-800 hidden">
                                Total: $<span id="total-amount">0.00</span>
                            </div>
                        </div>
                        
                        <button type="submit" class="w-full bg-blue-600 text-white py-3 px-4 rounded-md hover:bg-blue-700 transition flex items-center justify-center">
                            <i class="fas fa-paper-plane mr-2"></i> Place Order
                        </button>
                    </form>
                </div>
            </div>

            <!-- Query Tab Content -->
            <div id="query-content" class="p-6 hidden fade-in">
                <h2 class="text-2xl font-semibold mb-6 text-gray-800">Order Query</h2>
                
                <div class="bg-gray-50 p-6 rounded-lg mb-6">
                    <h3 class="text-lg font-medium text-gray-700 mb-4">Search Orders</h3>
                    <form id="query-form" class="space-y-4">
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                            <div>
                                <label for="query-name" class="block text-sm font-medium text-gray-700 mb-1">Name</label>
                                <input type="text" id="query-name" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <label for="query-table" class="block text-sm font-medium text-gray-700 mb-1">Table Number</label>
                                <input type="text" id="query-table" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <label for="query-date" class="block text-sm font-medium text-gray-700 mb-1">Date</label>
                                <input type="date" id="query-date" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                        </div>
                        
                        <button type="submit" class="bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 transition flex items-center justify-center">
                            <i class="fas fa-search mr-2"></i> Search Orders
                        </button>
                    </form>
                </div>
                
                <div id="query-results" class="border border-gray-200 rounded-lg overflow-hidden">
                    <div class="bg-gray-100 px-6 py-3 border-b border-gray-200 flex justify-between items-center">
                        <h3 class="font-medium text-gray-700">Search Results</h3>
                        <span id="results-count" class="text-sm text-gray-500">0 orders found</span>
                    </div>
                    <div id="orders-list" class="divide-y divide-gray-200">
                        <div class="p-4 text-center text-gray-500">
                            No orders to display. Perform a search to see results.
                        </div>
                    </div>
                </div>
            </div>

            <!-- Delete Tab Content -->
            <div id="manage-content" class="p-6 hidden fade-in">
                <h2 class="text-2xl font-semibold mb-6 text-gray-800">Manage Orders</h2>
                
                <div class="bg-gray-50 p-6 rounded-lg mb-6">
                    <h3 class="text-lg font-medium text-gray-700 mb-4">Delete Orders</h3>
                    <form id="delete-form" class="space-y-4">
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                            <div>
                                <label for="delete-id" class="block text-sm font-medium text-gray-700 mb-1">Order ID</label>
                                <input type="text" id="delete-id" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <label for="delete-name" class="block text-sm font-medium text-gray-700 mb-1">Name</label>
                                <input type="text" id="delete-name" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                            <div>
                                <label for="delete-table" class="block text-sm font-medium text-gray-700 mb-1">Table Number</label>
                                <input type="text" id="delete-table" class="w-full px-4 py-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500">
                            </div>
                        </div>
                        
                        <div class="flex space-x-4">
                            <button type="submit" class="bg-red-600 text-white py-2 px-4 rounded-md hover:bg-red-700 transition flex-1 flex items-center justify-center">
                                <i class="fas fa-trash-alt mr-2"></i> Delete Orders
                            </button>
                            <button type="button" onclick="clearAllOrders()" class="bg-gray-600 text-white py-2 px-4 rounded-md hover:bg-gray-700 transition flex-1 flex items-center justify-center">
                                <i class="fas fa-broom mr-2"></i> Clear All
                            </button>
                        </div>
                    </form>
                </div>
                
                <div id="delete-results" class="border border-gray-200 rounded-lg overflow-hidden">
                    <div class="bg-gray-100 px-6 py-3 border-b border-gray-200 flex justify-between items-center">
                        <h3 class="font-medium text-gray-700">All Orders</h3>
                        <span id="delete-count" class="text-sm text-gray-500">0 orders in system</span>
                    </div>
                    <div id="delete-list" class="divide-y divide-gray-200">
                        <div class="p-4 text-center text-gray-500">
                            No orders in the system.
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Success Modal -->
    <div id="success-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg p-6 max-w-md w-full mx-4 transform transition-all fade-in">
            <div class="text-center">
                <div class="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-green-100 mb-4">
                    <i class="fas fa-check text-green-600 text-xl"></i>
                </div>
                <h3 class="text-lg font-medium text-gray-900 mb-2" id="success-title">Success!</h3>
                <div class="mt-2 text-sm text-gray-500" id="success-message">
                    Your order has been placed successfully.
                </div>
                <div class="mt-4">
                    <button onclick="closeModal('success-modal')" type="button" class="inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none sm:text-sm">
                        OK
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Confirmation Modal -->
    <div id="confirm-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg p-6 max-w-md w-full mx-4 transform transition-all fade-in">
            <div class="text-center">
                <div class="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-red-100 mb-4">
                    <i class="fas fa-exclamation text-red-600 text-xl"></i>
                </div>
                <h3 class="text-lg font-medium text-gray-900 mb-2" id="confirm-title">Confirm Deletion</h3>
                <div class="mt-2 text-sm text-gray-500" id="confirm-message">
                    Are you sure you want to delete these orders? This action cannot be undone.
                </div>
                <div class="mt-4 flex justify-center space-x-4">
                    <button onclick="closeModal('confirm-modal')" type="button" class="inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none sm:text-sm">
                        Cancel
                    </button>
                    <button onclick="confirmDeletion()" type="button" class="inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none sm:text-sm">
                        Delete
                    </button>
                </div>
            </div>
        </div>
    </div>

    <script>
        // Sample data for meals
        const mealData = {
            breakfast: [
                { id: 1, name: "Pancakes", description: "Fluffy pancakes with maple syrup", price: 8.99, image: "🍞" },
                { id: 2, name: "Omelette", description: "Three-egg omelette with cheese and vegetables", price: 9.99, image: "🍳" },
                { id: 3, name: "French Toast", description: "Thick slices of bread dipped in egg batter", price: 7.99, image: "🥖" },
                { id: 4, name: "Yogurt Parfait", description: "Greek yogurt with granola and fresh berries", price: 6.99, image: "🥣" },
                { id: 5, name: "Breakfast Burrito", description: "Scrambled eggs, cheese, and sausage in a tortilla", price: 10.99, image: "🌯" }
            ],
            lunch: [
                { id: 6, name: "Caesar Salad", description: "Romaine lettuce, croutons, parmesan cheese", price: 10.99, image: "🥗" },
                { id: 7, name: "Club Sandwich", description: "Triple-decker sandwich with turkey, bacon, and veggies", price: 11.99, image: "🥪" },
                { id: 8, name: "Margherita Pizza", description: "Classic pizza with tomato sauce, mozzarella, and basil", price: 12.99, image: "🍕" },
                { id: 9, name: "Beef Burger", description: "Juicy beef patty with cheese and special sauce", price: 13.99, image: "🍔" },
                { id: 10, name: "Chicken Wrap", description: "Grilled chicken with veggies in a tortilla", price: 9.99, image: "🌯" }
            ],
            dinner: [
                { id: 11, name: "Grilled Salmon", description: "Fresh salmon with lemon butter sauce", price: 18.99, image: "🐟" },
                { id: 12, name: "Filet Mignon", description: "Tender beef filet with red wine reduction", price: 24.99, image: "🥩" },
                { id: 13, name: "Chicken Alfredo", description: "Fettuccine pasta with creamy alfredo sauce", price: 15.99, image: "🍝" },
                { id: 14, name: "Vegetable Stir Fry", description: "Assorted vegetables with tofu in teriyaki sauce", price: 13.99, image: "🥡" },
                { id: 15, name: "Shrimp Scampi", description: "Shrimp sautéed in garlic butter sauce", price: 19.99, image: "🍤" }
            ],
            supply: [
                { id: 16, name: "Bottled Water", description: "500ml mineral water", price: 1.99, image: "💧" },
                { id: 17, name: "Soft Drink", description: "Coke, Sprite, or Fanta", price: 2.99, image: "🥤" },
                { id: 18, name: "Coffee", description: "Freshly brewed coffee", price: 3.49, image: "☕" },
                { id: 19, name: "Tea", description: "Selection of herbal teas", price: 2.99, image: "🍵" },
                { id: 20, name: "Juice", description: "Orange, apple, or cranberry juice", price: 3.99, image: "🧃" }
            ]
        };

        // Orders storage
        let orders = JSON.parse(localStorage.getItem('orders')) || [];
        let selectedMeals = [];
        let currentMealType = 'breakfast';
        let ordersToDelete = [];

        // Initialize the app
        document.addEventListener('DOMContentLoaded', function() {
            // Set default tab
            switchTab('order');
            
            // Load breakfast meals by default
            loadMeals(currentMealType);
            
            // Set up event listeners
            document.getElementById('order-form').addEventListener('submit', placeOrder);
            document.getElementById('query-form').addEventListener('submit', queryOrders);
            document.getElementById('delete-form').addEventListener('submit', prepareDeletion);
            
            // Load all orders for delete tab
            loadAllOrders();
        });

        // Tab switching
        function switchTab(tab) {
            // Hide all content
            document.getElementById('order-content').classList.add('hidden');
            document.getElementById('query-content').classList.add('hidden');
            document.getElementById('manage-content').classList.add('hidden');
            
            // Remove active class from all tabs
            document.querySelectorAll('.tab-button').forEach(btn => {
                btn.classList.remove('tab-active');
            });
            
            // Show selected content and mark tab as active
            document.getElementById(`${tab}-content`).classList.remove('hidden');
            document.getElementById(`${tab}-tab`).classList.add('tab-active');
        }

        // Meal type selection
        function selectMealType(type) {
            currentMealType = type;
            loadMeals(type);
            
            // Update active button
            document.querySelectorAll('.meal-type-btn').forEach(btn => {
                btn.classList.remove('bg-blue-100', 'bg-green-100', 'bg-purple-100', 'bg-yellow-100');
                btn.classList.add('bg-blue-50', 'bg-green-50', 'bg-purple-50', 'bg-yellow-50');
            });
            
            const activeBtn = document.querySelector(`.meal-type-btn:nth-child(${
                type === 'breakfast' ? 1 : 
                type === 'lunch' ? 2 : 
                type === 'dinner' ? 3 : 4
            })`);
            
            activeBtn.classList.remove('bg-blue-50', 'bg-green-50', 'bg-purple-50', 'bg-yellow-50');
            activeBtn.classList.add(
                type === 'breakfast' ? 'bg-blue-100' : 
                type === 'lunch' ? 'bg-green-100' : 
                type === 'dinner' ? 'bg-purple-100' : 'bg-yellow-100'
            );
        }

        // Load meals for selected type
        function loadMeals(type) {
            const mealsContainer = document.getElementById('meal-cards');
            mealsContainer.innerHTML = '';
            
            mealData[type].forEach(meal => {
                const mealCard = document.createElement('div');
                mealCard.className = 'meal-card bg-white border border-gray-200 rounded-lg p-4 transition cursor-pointer hover:shadow-md';
                mealCard.innerHTML = `
                    <div class="flex items-start">
                        <div class="text-4xl mr-4">${meal.image}</div>
                        <div>
                            <h4 class="font-medium text-gray-800">${meal.name}</h4>
                            <p class="text-sm text-gray-600 mb-2">${meal.description}</p>
                            <div class="flex justify-between items-center">
                                <span class="font-medium text-blue-600">$${meal.price.toFixed(2)}</span>
                                <button onclick="addToOrder(${meal.id}, event)" class="text-sm bg-blue-50 text-blue-600 py-1 px-3 rounded hover:bg-blue-100 transition">
                                    <i class="fas fa-plus mr-1"></i> Add
                                </button>
                            </div>
                        </div>
                    </div>
                `;
                mealsContainer.appendChild(mealCard);
            });
        }

        // Add meal to order
        function addToOrder(mealId, event) {
            event.stopPropagation();
            
            // Find the meal in all categories
            let meal = null;
            for (const type in mealData) {
                meal = mealData[type].find(m => m.id === mealId);
                if (meal) break;
            }
            
            if (!meal) return;
            
            // Check if already added
            const existingIndex = selectedMeals.findIndex(m => m.id === meal.id);
            
            if (existingIndex >= 0) {
                selectedMeals[existingIndex].quantity += 1;
            } else {
                selectedMeals.push({
                    ...meal,
                    quantity: 1
                });
            }
            
            updateOrderSummary();
            
            // Show success feedback
            const button = event.target.closest('button');
            button.innerHTML = '<i class="fas fa-check mr-1"></i> Added';
            button.classList.remove('bg-blue-50', 'hover:bg-blue-100');
            button.classList.add('bg-green-50', 'hover:bg-green-100');
            
            setTimeout(() => {
                button.innerHTML = '<i class="fas fa-plus mr-1"></i> Add';
                button.classList.remove('bg-green-50', 'hover:bg-green-100');
                button.classList.add('bg-blue-50', 'hover:bg-blue-100');
            }, 1000);
        }

        // Update order summary
        function updateOrderSummary() {
            const orderItems = document.getElementById('order-items');
            const orderTotal = document.getElementById('order-total');
            
            if (selectedMeals.length === 0) {
                orderItems.innerHTML = '<p class="text-gray-500 text-sm">No items selected yet</p>';
                orderTotal.classList.add('hidden');
                return;
            }
            
            orderItems.innerHTML = '';
            let total = 0;
            
            selectedMeals.forEach((meal, index) => {
                const itemTotal = meal.price * meal.quantity;
                total += itemTotal;
                
                const item = document.createElement('div');
                item.className = 'flex justify-between items-center';
                item.innerHTML = `
                    <div>
                        <span class="font-medium text-gray-800">${meal.name}</span>
                        <span class="text-xs text-gray-500 ml-2">x${meal.quantity}</span>
                    </div>
                    <div class="flex items-center">
                        <span class="text-gray-700 mr-3">$${itemTotal.toFixed(2)}</span>
                        <button onclick="removeFromOrder(${index}, event)" class="text-red-500 hover:text-red-700">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>
                `;
                orderItems.appendChild(item);
            });
            
            document.getElementById('total-amount').textContent = total.toFixed(2);
            orderTotal.classList.remove('hidden');
        }

        // Remove item from order
        function removeFromOrder(index, event) {
            event.stopPropagation();
            selectedMeals.splice(index, 1);
            updateOrderSummary();
        }

        // Place order
        function placeOrder(e) {
            e.preventDefault();
            
            if (selectedMeals.length === 0) {
                showModal('Please select at least one item to order', 'Error', 'error');
                return;
            }
            
            const name = document.getElementById('name').value.trim();
            const table = document.getElementById('table').value.trim();
            const requests = document.getElementById('special-requests').value.trim();
            
            if (!name || !table) {
                showModal('Please provide your name and table number', 'Error', 'error');
                return;
            }
            
            // Calculate total
            const total = selectedMeals.reduce((sum, meal) => sum + (meal.price * meal.quantity), 0);
            
            // Create order
            const order = {
                id: Date.now(),
                name,
                table,
                specialRequests: requests,
                meals: [...selectedMeals],
                total,
                date: new Date().toISOString(),
                type: currentMealType
            };
            
            // Save to storage
            orders.push(order);
            localStorage.setItem('orders', JSON.stringify(orders));
            
            // Reset form
            document.getElementById('order-form').reset();
            selectedMeals = [];
            updateOrderSummary();
            
            // Show success
            showModal(`Order #${order.id} has been placed successfully. Total: $${total.toFixed(2)}`, 'Order Placed!', 'success');
            
            // Update delete tab
            loadAllOrders();
        }

        // Query orders
        function queryOrders(e) {
            e.preventDefault();
            
            const name = document.getElementById('query-name').value.trim().toLowerCase();
            const table = document.getElementById('query-table').value.trim().toLowerCase();
            const date = document.getElementById('query-date').value;
            
            let results = [...orders];
            
            if (name) {
                results = results.filter(order => order.name.toLowerCase().includes(name));
            }
            
            if (table) {
                results = results.filter(order => order.table.toLowerCase().includes(table));
            }
            
            if (date) {
                const searchDate = new Date(date).toDateString();
                results = results.filter(order => new Date(order.date).toDateString() === searchDate);
            }
            
            displayQueryResults(results);
        }

        // Display query results
        function displayQueryResults(results) {
            const container = document.getElementById('orders-list');
            const countElement = document.getElementById('results-count');
            
            countElement.textContent = `${results.length} order${results.length !== 1 ? 's' : ''} found`;
            
            if (results.length === 0) {
                container.innerHTML = '<div class="p-4 text-center text-gray-500">No orders match your search criteria.</div>';
                return;
            }
            
            container.innerHTML = '';
            
            results.forEach(order => {
                const orderElement = document.createElement('div');
                orderElement.className = 'p-4 hover:bg-gray-50';
                
                // Format date
                const orderDate = new Date(order.date);
                const dateStr = orderDate.toLocaleDateString();
                const timeStr = orderDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
                
                orderElement.innerHTML = `
                    <div class="flex justify-between items-start mb-2">
                        <div>
                            <span class="font-medium">Order #${order.id}</span>
                            <span class="text-xs bg-blue-100 text-blue-800 py-1 px-2 rounded-full ml-2 capitalize">${order.type}</span>
                        </div>
                        <span class="text-sm text-gray-500">${dateStr} at ${timeStr}</span>
                    </div>
                    <div class="text-sm mb-2">
                        <span class="font-medium">${order.name}</span> (Table ${order.table})
                    </div>
                    <div class="text-sm mb-3">
                        ${order.meals.map(meal => `${meal.name} x${meal.quantity}`).join(', ')}
                    </div>
                    <div class="flex justify-between items-center text-sm">
                        <div>
                            ${order.specialRequests ? `<span class="text-gray-600"><i class="fas fa-comment-alt mr-1"></i> ${order.specialRequests}</span>` : ''}
                        </div>
                        <span class="font-medium">$${order.total.toFixed(2)}</span>
                    </div>
                `;
                
                container.appendChild(orderElement);
            });
        }

        // Prepare for deletion
        function prepareDeletion(e) {
            e.preventDefault();
            
            const id = document.getElementById('delete-id').value.trim();
            const name = document.getElementById('delete-name').value.trim().toLowerCase();
            const table = document.getElementById('delete-table').value.trim().toLowerCase();
            
            ordersToDelete = [];
            
            if (id || name || table) {
                // Filter orders based on criteria
                ordersToDelete = orders.filter(order => {
                    return (id && order.id.toString().includes(id)) ||
                           (name && order.name.toLowerCase().includes(name)) ||
                           (table && order.table.toLowerCase().includes(table));
                });
            } else {
                // If no criteria, select all
                ordersToDelete = [...orders];
            }
            
            if (ordersToDelete.length === 0) {
                showModal('No orders match your criteria', 'No Orders Found', 'error');
                return;
            }
            
            // Show confirmation
            document.getElementById('confirm-message').textContent = 
                `Are you sure you want to delete ${ordersToDelete.length} order${ordersToDelete.length !== 1 ? 's' : ''}? This action cannot be undone.`;
            showModal('', 'Confirm Deletion', 'confirm');
        }

        // Confirm deletion
        function confirmDeletion() {
            // Remove orders from storage
            orders = orders.filter(order => !ordersToDelete.some(delOrder => delOrder.id === order.id));
            localStorage.setItem('orders', JSON.stringify(orders));
            
            // Close modal and update UI
            closeModal('confirm-modal');
            showModal(`${ordersToDelete.length} order${ordersToDelete.length !== 1 ? 's' : ''} deleted successfully`, 'Success', 'success');
            
            // Reset form and reload
            document.getElementById('delete-form').reset();
            loadAllOrders();
            
            // Clear selection
            ordersToDelete = [];
        }

        // Clear all orders
        function clearAllOrders() {
            if (orders.length === 0) {
                showModal('There are no orders to clear', 'No Orders', 'error');
                return;
            }
            
            ordersToDelete = [...orders];
            document.getElementById('confirm-message').textContent = 
                `Are you sure you want to delete ALL ${orders.length} orders? This action cannot be undone.`;
            showModal('', 'Confirm Deletion', 'confirm');
        }

        // Load all orders for delete tab
        function loadAllOrders() {
            const container = document.getElementById('delete-list');
            const countElement = document.getElementById('delete-count');
            
            countElement.textContent = `${orders.length} order${orders.length !== 1 ? 's' : ''} in system`;
            
            if (orders.length === 0) {
                container.innerHTML = '<div class="p-4 text-center text-gray-500">No orders in the system.</div>';
                return;
            }
            
            container.innerHTML = '';
            
            // Group by date
            const ordersByDate = {};
            orders.forEach(order => {
                const date = new Date(order.date).toDateString();
                if (!ordersByDate[date]) {
                    ordersByDate[date] = [];
                }
                ordersByDate[date].push(order);
            });
            
            // Display by date
            for (const date in ordersByDate) {
                const dateHeader = document.createElement('div');
                dateHeader.className = 'bg-gray-50 px-4 py-2 text-sm font-medium text-gray-700';
                dateHeader.textContent = date;
                container.appendChild(dateHeader);
                
                ordersByDate[date].forEach(order => {
                    const orderElement = document.createElement('div');
                    orderElement.className = 'p-4 hover:bg-gray-50 flex justify-between items-center';
                    
                    // Format time
                    const orderDate = new Date(order.date);
                    const timeStr = orderDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
                    
                    orderElement.innerHTML = `
                        <div>
                            <div class="flex items-center mb-1">
                                <span class="font-medium mr-2">#${order.id}</span>
                                <span class="text-xs bg-blue-100 text-blue-800 py-1 px-2 rounded-full capitalize">${order.type}</span>
                            </div>
                            <div class="text-sm">
                                ${order.name} (Table ${order.table}) • ${timeStr}
                            </div>
                        </div>
                        <div class="text-right">
                            <div class="font-medium">$${order.total.toFixed(2)}</div>
                            <button onclick="deleteSingleOrder(${order.id}, event)" class="text-red-500 hover:text-red-700 text-sm mt-1">
                                <i class="fas fa-trash-alt"></i>
                            </button>
                        </div>
                    `;
                    
                    container.appendChild(orderElement);
                });
            }
        }

        // Delete single order
        function deleteSingleOrder(orderId, event) {
            event.stopPropagation();
            
            ordersToDelete = orders.filter(order => order.id === orderId);
            
            document.getElementById('confirm-message').textContent = 
                `Are you sure you want to delete order #${orderId}? This action cannot be undone.`;
            showModal('', 'Confirm Deletion', 'confirm');
        }

        // Show modal
        function showModal(message, title, type) {
            const modal = document.getElementById(`${type}-modal`);
            
            if (title) document.getElementById(`${type}-title`).textContent = title;
            if (message) document.getElementById(`${type}-message`).textContent = message;
            
            modal.classList.remove('hidden');
        }

        // Close modal
        function closeModal(modalId) {
            document.getElementById(modalId).classList.add('hidden');
        }
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Yghubpush/dinner" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>