<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nep-YTDL - YouTube Video Downloader</title>
    <link rel="icon" type="image/png" href="images/video.svg">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
    
    <style>
        body {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            font-family: 'Poppins', sans-serif;
            color: #fff;
            margin: 0;
            padding: 0;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .navbar {
            background-color: rgba(0, 0, 0, 0.2);
            backdrop-filter: blur(10px);
            padding: 15px 0;
        }

        .navbar img {
            height: 40px;
            margin-right: 10px;
        }

        .navbar-brand {
            font-size: 1.5rem;
            font-weight: 600;
            color: #fff;
        }

        .container {
            flex: 1;
            max-width: 800px;
            margin: 50px auto;
            background-color: rgba(255, 255, 255, 0.1);
            padding: 30px;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            backdrop-filter: blur(10px);
        }

        h1 {
            text-align: center;
            margin-bottom: 30px;
            font-weight: 600;
            letter-spacing: 1px;
            color: #fff;
        }

        video {
            display: block;
            max-width: 100%;
            height: auto;
            margin: 0 auto 30px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
        }

        .form-group label {
            font-weight: 600;
            margin-bottom: 10px;
        }

        .form-control {
            background-color: rgba(255, 255, 255, 0.1);
            border: none;
            border-radius: 10px;
            color: #fff;
            padding: 12px;
        }

        .list-group-item {
            background-color: rgba(255, 255, 255, 0.05);
            border: none;
            border-radius: 10px;
            margin-bottom: 10px;
            padding: 15px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            transition: all 0.3s ease;
        }

        .list-group-item:hover {
            background-color: rgba(255, 255, 255, 0.1);
            transform: translateY(-2px);
        }

        .btn {
            padding: 10px 20px;
            background-color: #e50914;
            color: #fff;
            border: none;
            border-radius: 10px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            transition: all 0.3s ease;
        }

        .btn:hover {
            background-color: #b00710;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(229, 9, 20, 0.3);
        }

        .download-icon {
            margin-right: 8px;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg">
        <div class="container">
            <a class="navbar-brand" href="#">
                <img src="images/video.svg" alt="YouTube Logo">
                Nep-YTDL
            </a>
        </div>
    </nav>

    <div class="container">
        <h1>YouTube Video Downloader</h1>
        <video controls class="mb-4">
            <source src="/stream?url=<%= encodeURIComponent(url) %>&quality=<%= encodeURIComponent(formats[0].itag) %>" type="video/mp4">
            Your browser does not support the video tag.
        </video>
        
        <div class="form-group">
            <label for="format">Select Format:</label>
            <select id="format" class="form-control" onchange="changeFormat(this)">
                <option value="webm">WEBM</option>
                <option value="mp4">MP4</option>
            </select>
        </div>
        
        <div id="download-options" class="mt-4">
            <ul class="list-group">
                <% formats.forEach(function(format) { %>
                    <li class="list-group-item <% if (format.container === 'mp4') { %>mp4 <% } else if (format.container === 'webm') { %>webm <% } %>">
                        <span><%= format.qualityLabel || format.resolution %> (<%= format.container %>)</span>
                        <a href="/download?url=<%= url %>&quality=<%= format.itag %>&title=<%= encodeURIComponent(title) %>" class="btn">
                            <i class="fas fa-download download-icon"></i> Download
                        </a>
                    </li>
                <% }); %>
            </ul>
        </div>
    </div>

    <script>
        function changeFormat(select) {
            const selectedFormat = select.value;
            const options = document.querySelectorAll('#download-options .list-group-item');

            options.forEach(option => {
                option.style.display = option.classList.contains(selectedFormat) ? 'flex' : 'none';
            });
        }
    </script>
</body>
</html>