File size: 23,577 Bytes
6d5721b
 
 
 
 
bc9545e
dd5846a
bc9545e
 
 
 
 
 
77bca8d
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77bca8d
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77bca8d
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77bca8d
bc9545e
 
 
 
 
 
77bca8d
bc9545e
 
 
 
77bca8d
bc9545e
 
 
77bca8d
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd5846a
 
6d5721b
77bca8d
bc9545e
 
 
 
 
 
 
 
 
 
f848982
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22fa71e
bc9545e
 
 
 
 
e8ac6b1
bc9545e
 
 
 
 
 
 
9274027
bc9545e
 
 
 
 
 
 
dd5846a
 
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd5846a
 
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9274027
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
e8ac6b1
bc9545e
e8ac6b1
bc9545e
 
 
 
 
 
 
 
 
 
77bca8d
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8ac6b1
bc9545e
77bca8d
bc9545e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f160a3
22fa71e
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Video Streaming Platform</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #0f0f0f;
            color: #fff;
            line-height: 1.6;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 0 20px;
        }

        /* Header */
        header {
            background: #212121;
            padding: 1rem 0;
            position: sticky;
            top: 0;
            z-index: 100;
            border-bottom: 1px solid #333;
        }

        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 1rem;
        }

        .logo {
            font-size: 1.8rem;
            font-weight: bold;
            color: #ff6b6b;
            cursor: pointer;
            transition: color 0.3s ease;
        }

        .logo:hover {
            color: #ff5252;
        }

        .search-container {
            flex: 1;
            max-width: 500px;
            position: relative;
        }

        #searchInput {
            width: 100%;
            padding: 12px 20px;
            background: #333;
            border: 2px solid #444;
            border-radius: 25px;
            color: #fff;
            font-size: 16px;
            transition: all 0.3s ease;
        }

        #searchInput:focus {
            outline: none;
            border-color: #ff6b6b;
            background: #404040;
        }

        #searchInput::placeholder {
            color: #aaa;
        }

        /* Main Content */
        main {
            min-height: calc(100vh - 200px);
            padding: 2rem 0;
        }

        /* Video Grid */
        .video-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
            gap: 1.5rem;
            margin-bottom: 2rem;
        }

        .video-card {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
            transition: all 0.3s ease;
            cursor: pointer;
            border: 2px solid transparent;
        }

        .video-card:hover {
            transform: translateY(-8px);
            border-color: #ff6b6b;
            box-shadow: 0 12px 30px rgba(255, 107, 107, 0.3);
        }

        .video-thumbnail {
            width: 100%;
            height: 180px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }

        .play-icon {
            width: 60px;
            height: 60px;
            background: rgba(255, 255, 255, 0.9);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            color: #333;
            transition: all 0.3s ease;
        }

        .video-card:hover .play-icon {
            transform: scale(1.1);
            background: #ff6b6b;
            color: #fff;
        }

        .video-info {
            padding: 1rem;
        }

        .video-title {
            font-size: 1.1rem;
            font-weight: 600;
            color: #fff;
            margin-bottom: 0.5rem;
        }

        .video-meta {
            color: #aaa;
            font-size: 0.9rem;
        }

        /* Video Player Page */
        .player-container {
            display: none;
        }

        .player-container.active {
            display: block;
        }

        .video-player-section {
            background: #1e1e1e;
            border-radius: 12px;
            padding: 1rem;
            margin-bottom: 2rem;
        }

        .video-player {
            width: 100%;
            max-width: 900px;
            height: auto;
            border-radius: 8px;
            margin-bottom: 1rem;
        }

        .video-details h2 {
            font-size: 1.5rem;
            margin-bottom: 1rem;
            color: #fff;
        }

        .back-button {
            background: #ff6b6b;
            color: #fff;
            border: none;
            padding: 12px 24px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            margin-bottom: 1rem;
        }

        .back-button:hover {
            background: #ff5252;
            transform: translateY(-2px);
        }

        .recommendations {
            margin-top: 2rem;
        }

        .recommendations h3 {
            margin-bottom: 1rem;
            color: #fff;
            font-size: 1.3rem;
        }

        .recommendations-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 1rem;
        }

        .recommendation-card {
            background: #2a2a2a;
            border-radius: 8px;
            padding: 1rem;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 1px solid #444;
        }

        .recommendation-card:hover {
            background: #333;
            border-color: #ff6b6b;
        }

        .recommendation-title {
            font-weight: 600;
            margin-bottom: 0.5rem;
        }

        /* Pagination */
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 0.5rem;
            margin: 2rem 0;
            flex-wrap: wrap;
        }

        .pagination button {
            background: #333;
            color: #fff;
            border: none;
            padding: 10px 15px;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 14px;
        }

        .pagination button:hover:not(:disabled) {
            background: #ff6b6b;
            transform: translateY(-2px);
        }

        .pagination button:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

        .pagination button.active {
            background: #ff6b6b;
        }

        .pagination-info {
            color: #aaa;
            margin: 0 1rem;
            font-size: 14px;
        }

        /* No Results */
        .no-results {
            text-align: center;
            padding: 3rem;
            color: #aaa;
        }

        .no-results h3 {
            font-size: 1.5rem;
            margin-bottom: 1rem;
        }

        .no-results p {
            font-size: 1.1rem;
        }

        /* Loading */
        .loading {
            text-align: center;
            padding: 3rem;
            color: #aaa;
        }

        .loading-spinner {
            width: 50px;
            height: 50px;
            border: 3px solid #333;
            border-top: 3px solid #ff6b6b;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto 1rem;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* Responsive Design */
        @media (max-width: 768px) {
            .header-content {
                flex-direction: column;
                text-align: center;
            }

            .search-container {
                max-width: 100%;
            }

            .video-grid {
                grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
                gap: 1rem;
            }

            .recommendations-grid {
                grid-template-columns: 1fr;
            }

            .pagination {
                gap: 0.25rem;
            }

            .pagination button {
                padding: 8px 12px;
                font-size: 12px;
            }
        }

        @media (max-width: 480px) {
            .video-grid {
                grid-template-columns: 1fr;
            }

            .video-thumbnail {
                height: 200px;
            }
        }
    </style>
</head>
<body>
    <header>
        <div class="container">
            <div class="header-content">
                <div class="logo" onclick="showVideoList()">📺 VideoHub</div>
                <div class="search-container">
                    <input type="text" id="searchInput" placeholder="Search videos..." oninput="handleSearch()">
                </div>
            </div>
        </div>
    </header>

    <main>
        <div class="container">
            <!-- Video List View -->
            <div id="videoListContainer">
                <div id="loadingIndicator" class="loading">
                    <div class="loading-spinner"></div>
                    <p>Loading videos...</p>
                </div>
                
                <div id="videoGrid" class="video-grid"></div>
                
                <div id="noResults" class="no-results" style="display: none;">
                    <h3>No videos found</h3>
                    <p>Try adjusting your search terms</p>
                </div>
                
                <div id="paginationContainer" class="pagination"></div>
            </div>

            <!-- Video Player View -->
            <div id="videoPlayerContainer" class="player-container">
                <button class="back-button" onclick="showVideoList()">← Back to Videos</button>
                
                <div class="video-player-section">
                    <video id="videoPlayer" class="video-player" controls>
                        Your browser does not support the video tag.
                    </video>
                    
                    <div class="video-details">
                        <h2 id="currentVideoTitle">Video Title</h2>
                    </div>
                </div>

                <div class="recommendations">
                    <h3>Up Next</h3>
                    <div id="recommendationsGrid" class="recommendations-grid"></div>
                </div>
            </div>
        </div>
    </main>

    <script>
        // Global state
        let allVideos = [];
        let filteredVideos = [];
        let currentPage = 1;
        const videosPerPage = 12;
        let currentVideoIndex = -1;
        let searchQuery = '';

        // Sample data (replace with actual database.json loading)
        const sampleData = [
            { "title": "E01 - Introduction", "url": "https://example.com/video1.mkv" },
            { "title": "E02 - Getting Started", "url": "https://example.com/video2.mkv" },
            { "title": "E03 - Advanced Concepts", "url": "https://example.com/video3.mkv" },
            { "title": "E04 - Best Practices", "url": "https://example.com/video4.mkv" },
            { "title": "E05 - Case Studies", "url": "https://example.com/video5.mkv" },
            { "title": "E06 - Implementation", "url": "https://example.com/video6.mkv" },
            { "title": "E07 - Testing", "url": "https://example.com/video7.mkv" },
            { "title": "E08 - Deployment", "url": "https://example.com/video8.mkv" },
            { "title": "E09 - Monitoring", "url": "https://example.com/video9.mkv" },
            { "title": "E10 - Optimization", "url": "https://example.com/video10.mkv" },
            { "title": "E11 - Security", "url": "https://example.com/video11.mkv" },
            { "title": "E12 - Maintenance", "url": "https://example.com/video12.mkv" },
            { "title": "E13 - Troubleshooting", "url": "https://example.com/video13.mkv" },
            { "title": "E14 - Future Trends", "url": "https://example.com/video14.mkv" },
            { "title": "E15 - Conclusion", "url": "https://example.com/video15.mkv" }
        ];

        // Initialize the application
        async function initApp() {
            try {
                // Try to load from database.json, fallback to sample data
                await loadVideos();
                setupEventListeners();
                handleURLHash();
            } catch (error) {
                console.error('Error initializing app:', error);
                // Use sample data as fallback
                allVideos = [...sampleData];
                filteredVideos = [...allVideos];
                hideLoading();
                renderVideoGrid();
                renderPagination();
            }
        }

        // Load videos from database.json
        async function loadVideos() {
            try {
                const response = await fetch('database.json');
                if (response.ok) {
                    const data = await response.json();
                    allVideos = data.sort((a, b) => a.title.localeCompare(b.title));
                } else {
                    throw new Error('Failed to load database.json');
                }
            } catch (error) {
                console.warn('Could not load database.json, using sample data:', error);
                allVideos = [...sampleData];
            }
            
            filteredVideos = [...allVideos];
            hideLoading();
            renderVideoGrid();
            renderPagination();
        }

        // Setup event listeners
        function setupEventListeners() {
            // Handle browser back/forward
            window.addEventListener('popstate', handleURLHash);
            
            // Handle video player events
            const videoPlayer = document.getElementById('videoPlayer');
            videoPlayer.addEventListener('error', handleVideoError);
            videoPlayer.addEventListener('loadedmetadata', handleVideoLoaded);
        }

        // Handle URL hash changes
        function handleURLHash() {
            const hash = window.location.hash;
            if (hash.startsWith('#play=')) {
                const videoTitle = decodeURIComponent(hash.substring(6));
                const videoIndex = allVideos.findIndex(v => v.title === videoTitle);
                if (videoIndex !== -1) {
                    playVideo(videoIndex);
                } else {
                    showVideoList();
                }
            } else {
                showVideoList();
            }
        }

        // Hide loading indicator
        function hideLoading() {
            document.getElementById('loadingIndicator').style.display = 'none';
        }

        // Handle search input
        function handleSearch() {
            const query = document.getElementById('searchInput').value.toLowerCase().trim();
            searchQuery = query;
            
            if (query === '') {
                filteredVideos = [...allVideos];
            } else {
                filteredVideos = allVideos.filter(video => 
                    video.title.toLowerCase().includes(query)
                );
            }
            
            currentPage = 1;
            renderVideoGrid();
            renderPagination();
        }

        // Render video grid
        function renderVideoGrid() {
            const grid = document.getElementById('videoGrid');
            const noResults = document.getElementById('noResults');
            
            if (filteredVideos.length === 0) {
                grid.innerHTML = '';
                noResults.style.display = 'block';
                return;
            }
            
            noResults.style.display = 'none';
            
            const startIndex = (currentPage - 1) * videosPerPage;
            const endIndex = startIndex + videosPerPage;
            const videosToShow = filteredVideos.slice(startIndex, endIndex);
            
            grid.innerHTML = videosToShow.map((video, index) => {
                const actualIndex = allVideos.findIndex(v => v.title === video.title);
                return `
                    <div class="video-card" onclick="playVideo(${actualIndex})">
                        <div class="video-thumbnail">
                            <div class="play-icon">▶</div>
                        </div>
                        <div class="video-info">
                            <div class="video-title">${escapeHtml(video.title)}</div>
                            <div class="video-meta">Click to play</div>
                        </div>
                    </div>
                `;
            }).join('');
        }

        // Render pagination
        function renderPagination() {
            const container = document.getElementById('paginationContainer');
            const totalPages = Math.ceil(filteredVideos.length / videosPerPage);
            
            if (totalPages <= 1) {
                container.innerHTML = '';
                return;
            }
            
            let paginationHTML = '';
            
            // Previous button
            paginationHTML += `
                <button onclick="changePage(${currentPage - 1})" ${currentPage === 1 ? 'disabled' : ''}>
                    ← Previous
                </button>
            `;
            
            // Page numbers
            const maxVisiblePages = 5;
            let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2));
            let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1);
            
            if (endPage - startPage + 1 < maxVisiblePages) {
                startPage = Math.max(1, endPage - maxVisiblePages + 1);
            }
            
            if (startPage > 1) {
                paginationHTML += `<button onclick="changePage(1)">1</button>`;
                if (startPage > 2) {
                    paginationHTML += `<span class="pagination-info">...</span>`;
                }
            }
            
            for (let i = startPage; i <= endPage; i++) {
                paginationHTML += `
                    <button onclick="changePage(${i})" ${i === currentPage ? 'class="active"' : ''}>
                        ${i}
                    </button>
                `;
            }
            
            if (endPage < totalPages) {
                if (endPage < totalPages - 1) {
                    paginationHTML += `<span class="pagination-info">...</span>`;
                }
                paginationHTML += `<button onclick="changePage(${totalPages})">${totalPages}</button>`;
            }
            
            // Next button
            paginationHTML += `
                <button onclick="changePage(${currentPage + 1})" ${currentPage === totalPages ? 'disabled' : ''}>
                    Next →
                </button>
            `;
            
            // Page info
            const startItem = (currentPage - 1) * videosPerPage + 1;
            const endItem = Math.min(currentPage * videosPerPage, filteredVideos.length);
            paginationHTML += `
                <span class="pagination-info">
                    ${startItem}-${endItem} of ${filteredVideos.length} videos
                </span>
            `;
            
            container.innerHTML = paginationHTML;
        }

        // Change page
        function changePage(page) {
            const totalPages = Math.ceil(filteredVideos.length / videosPerPage);
            if (page >= 1 && page <= totalPages) {
                currentPage = page;
                renderVideoGrid();
                renderPagination();
                
                // Scroll to top
                window.scrollTo({ top: 0, behavior: 'smooth' });
            }
        }

        // Play video
        function playVideo(videoIndex) {
            if (videoIndex < 0 || videoIndex >= allVideos.length) return;
            
            currentVideoIndex = videoIndex;
            const video = allVideos[videoIndex];
            
            // Update URL hash
            window.history.pushState(null, null, `#play=${encodeURIComponent(video.title)}`);
            
            // Hide video list, show player
            document.getElementById('videoListContainer').style.display = 'none';
            document.getElementById('videoPlayerContainer').classList.add('active');
            
            // Set up video player
            const videoPlayer = document.getElementById('videoPlayer');
            videoPlayer.src = video.url;
            
            // Update video title
            document.getElementById('currentVideoTitle').textContent = video.title;
            
            // Generate recommendations
            generateRecommendations();
            
            // Scroll to top
            window.scrollTo({ top: 0, behavior: 'smooth' });
        }

        // Generate recommendations
        function generateRecommendations() {
            const grid = document.getElementById('recommendationsGrid');
            const recommendations = [];
            
            // Get next 5 videos in sequence
            for (let i = 1; i <= 5; i++) {
                const nextIndex = currentVideoIndex + i;
                if (nextIndex < allVideos.length) {
                    recommendations.push({ video: allVideos[nextIndex], index: nextIndex });
                }
            }
            
            // If we don't have enough recommendations, add some from the beginning
            let startIndex = 0;
            while (recommendations.length < 5 && startIndex < allVideos.length) {
                if (startIndex !== currentVideoIndex && 
                    !recommendations.some(r => r.index === startIndex)) {
                    recommendations.push({ video: allVideos[startIndex], index: startIndex });
                }
                startIndex++;
            }
            
            grid.innerHTML = recommendations.map(({ video, index }) => `
                <div class="recommendation-card" onclick="playVideo(${index})">
                    <div class="recommendation-title">${escapeHtml(video.title)}</div>
                    <div class="video-meta">Click to play</div>
                </div>
            `).join('');
        }

        // Show video list
        function showVideoList() {
            // Update URL
            window.history.pushState(null, null, window.location.pathname);
            
            // Hide player, show list
            document.getElementById('videoPlayerContainer').classList.remove('active');
            document.getElementById('videoListContainer').style.display = 'block';
            
            // Pause current video
            const videoPlayer = document.getElementById('videoPlayer');
            videoPlayer.pause();
        }

        // Handle video errors
        function handleVideoError(event) {
            console.error('Video error:', event);
            alert('Error loading video. Please check the video URL or try again later.');
        }

        // Handle video loaded
        function handleVideoLoaded(event) {
            console.log('Video loaded successfully');
        }

        // Utility function to escape HTML
        function escapeHtml(text) {
            const div = document.createElement('div');
            div.textContent = text;
            return div.innerHTML;
        }

        // Initialize the app when DOM is loaded
        document.addEventListener('DOMContentLoaded', initApp);
    </script>
</body>
</html>