<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>RTube - Edit Video</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                max-width: 600px;
                margin: 0 auto;
                padding: 20px;
                background-color: #1a1a1a;
                color: #fff;
            }
            .header {
                display: flex;
                align-items: center;
                gap: 20px;
                margin-bottom: 30px;
            }
            .back-link {
                color: #888;
                text-decoration: none;
                font-size: 14px;
            }
            .back-link:hover {
                color: #fff;
            }
            h1 {
                margin: 0;
            }
            .form-group {
                margin-bottom: 20px;
            }
            label {
                display: block;
                margin-bottom: 8px;
                font-size: 14px;
                color: #aaa;
            }
            input[type="text"], textarea, select {
                width: 100%;
                padding: 12px;
                border: 1px solid #444;
                border-radius: 5px;
                background-color: #2a2a2a;
                color: #fff;
                font-size: 14px;
                box-sizing: border-box;
            }
            input[type="text"]:focus, textarea:focus, select:focus {
                outline: none;
                border-color: #4CAF50;
            }
            textarea {
                min-height: 100px;
                resize: vertical;
            }
            select {
                cursor: pointer;
            }
            .btn-submit {
                padding: 12px 24px;
                background-color: #4CAF50;
                color: white;
                border: none;
                border-radius: 5px;
                font-size: 14px;
                cursor: pointer;
                transition: background-color 0.2s;
            }
            .btn-submit:hover {
                background-color: #45a049;
            }
            .flash-messages {
                margin-bottom: 20px;
            }
            .flash-message {
                padding: 12px;
                border-radius: 4px;
                margin-bottom: 10px;
                font-size: 14px;
            }
            .flash-error {
                background-color: #5c1a1a;
                color: #ff6b6b;
                border: 1px solid #8B0000;
            }
            .flash-success {
                background-color: #1a3d1a;
                color: #81C784;
                border: 1px solid #2E7D32;
            }
            .video-info {
                background-color: #2a2a2a;
                padding: 15px;
                border-radius: 5px;
                margin-bottom: 20px;
                font-size: 13px;
                color: #888;
            }
            .video-info span {
                display: block;
                margin-bottom: 5px;
            }
            .video-info strong {
                color: #aaa;
            }
            footer {
                margin-top: 50px;
                padding-top: 20px;
                border-top: 1px solid #333;
                text-align: center;
                color: #666;
                font-size: 12px;
            }
            .admin-section {
                border: 1px solid #8B0000;
                border-radius: 5px;
                padding: 15px;
                background-color: #2a1a1a;
            }
            .admin-section label {
                color: #ff6b6b;
            }
        </style>
        <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}">
    <link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}">

</head>
    <body>
        <div class="header">
            <a href="{{ url_for('videos.watch_video', v=video.short_id) }}" class="back-link">&larr; Back to Video</a>
            <h1>Edit Video</h1>
        </div>

        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
        <div class="flash-messages">
            {% for category, message in messages %}
            <div class="flash-message flash-{{ category }}">{{ message }}</div>
            {% endfor %}
        </div>
        {% endif %}
        {% endwith %}

        <div class="video-info">
            <span><strong>ID:</strong> {{ video.short_id }}</span>
            <span><strong>Filename:</strong> {{ video.filename }}</span>
            <span><strong>Owner:</strong> {{ video.owner_username or 'Unknown' }}</span>
            <span><strong>Views:</strong> {{ video.view_count }}</span>
            <span><strong>Created:</strong> {{ video.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
        </div>

        <form method="post">
            <div class="form-group">
                <label for="title">Title</label>
                <input type="text" id="title" name="title" maxlength="255" value="{{ video.title or '' }}">
            </div>
            <div class="form-group">
                <label for="description">Description</label>
                <textarea id="description" name="description">{{ video.description or '' }}</textarea>
            </div>
            <div class="form-group">
                <label for="language">Language</label>
                <select id="language" name="language">
                    <option value="">-- No language --</option>
                    <option value="af" {{ 'selected' if video.language == 'af' else '' }}>Afrikaans</option>
                    <option value="sq" {{ 'selected' if video.language == 'sq' else '' }}>Albanian</option>
                    <option value="am" {{ 'selected' if video.language == 'am' else '' }}>Amharic</option>
                    <option value="ar" {{ 'selected' if video.language == 'ar' else '' }}>Arabic</option>
                    <option value="hy" {{ 'selected' if video.language == 'hy' else '' }}>Armenian</option>
                    <option value="az" {{ 'selected' if video.language == 'az' else '' }}>Azerbaijani</option>
                    <option value="eu" {{ 'selected' if video.language == 'eu' else '' }}>Basque</option>
                    <option value="be" {{ 'selected' if video.language == 'be' else '' }}>Belarusian</option>
                    <option value="bn" {{ 'selected' if video.language == 'bn' else '' }}>Bengali</option>
                    <option value="bs" {{ 'selected' if video.language == 'bs' else '' }}>Bosnian</option>
                    <option value="bg" {{ 'selected' if video.language == 'bg' else '' }}>Bulgarian</option>
                    <option value="my" {{ 'selected' if video.language == 'my' else '' }}>Burmese</option>
                    <option value="ca" {{ 'selected' if video.language == 'ca' else '' }}>Catalan</option>
                    <option value="zh" {{ 'selected' if video.language == 'zh' else '' }}>Chinese</option>
                    <option value="hr" {{ 'selected' if video.language == 'hr' else '' }}>Croatian</option>
                    <option value="cs" {{ 'selected' if video.language == 'cs' else '' }}>Czech</option>
                    <option value="da" {{ 'selected' if video.language == 'da' else '' }}>Danish</option>
                    <option value="nl" {{ 'selected' if video.language == 'nl' else '' }}>Dutch</option>
                    <option value="en" {{ 'selected' if video.language == 'en' else '' }}>English</option>
                    <option value="et" {{ 'selected' if video.language == 'et' else '' }}>Estonian</option>
                    <option value="fi" {{ 'selected' if video.language == 'fi' else '' }}>Finnish</option>
                    <option value="fr" {{ 'selected' if video.language == 'fr' else '' }}>French</option>
                    <option value="gl" {{ 'selected' if video.language == 'gl' else '' }}>Galician</option>
                    <option value="ka" {{ 'selected' if video.language == 'ka' else '' }}>Georgian</option>
                    <option value="de" {{ 'selected' if video.language == 'de' else '' }}>German</option>
                    <option value="el" {{ 'selected' if video.language == 'el' else '' }}>Greek</option>
                    <option value="gu" {{ 'selected' if video.language == 'gu' else '' }}>Gujarati</option>
                    <option value="ht" {{ 'selected' if video.language == 'ht' else '' }}>Haitian Creole</option>
                    <option value="ha" {{ 'selected' if video.language == 'ha' else '' }}>Hausa</option>
                    <option value="he" {{ 'selected' if video.language == 'he' else '' }}>Hebrew</option>
                    <option value="hi" {{ 'selected' if video.language == 'hi' else '' }}>Hindi</option>
                    <option value="hu" {{ 'selected' if video.language == 'hu' else '' }}>Hungarian</option>
                    <option value="is" {{ 'selected' if video.language == 'is' else '' }}>Icelandic</option>
                    <option value="ig" {{ 'selected' if video.language == 'ig' else '' }}>Igbo</option>
                    <option value="id" {{ 'selected' if video.language == 'id' else '' }}>Indonesian</option>
                    <option value="ga" {{ 'selected' if video.language == 'ga' else '' }}>Irish</option>
                    <option value="it" {{ 'selected' if video.language == 'it' else '' }}>Italian</option>
                    <option value="ja" {{ 'selected' if video.language == 'ja' else '' }}>Japanese</option>
                    <option value="jv" {{ 'selected' if video.language == 'jv' else '' }}>Javanese</option>
                    <option value="kn" {{ 'selected' if video.language == 'kn' else '' }}>Kannada</option>
                    <option value="kk" {{ 'selected' if video.language == 'kk' else '' }}>Kazakh</option>
                    <option value="km" {{ 'selected' if video.language == 'km' else '' }}>Khmer</option>
                    <option value="ko" {{ 'selected' if video.language == 'ko' else '' }}>Korean</option>
                    <option value="ku" {{ 'selected' if video.language == 'ku' else '' }}>Kurdish</option>
                    <option value="ky" {{ 'selected' if video.language == 'ky' else '' }}>Kyrgyz</option>
                    <option value="lo" {{ 'selected' if video.language == 'lo' else '' }}>Lao</option>
                    <option value="la" {{ 'selected' if video.language == 'la' else '' }}>Latin</option>
                    <option value="lv" {{ 'selected' if video.language == 'lv' else '' }}>Latvian</option>
                    <option value="lt" {{ 'selected' if video.language == 'lt' else '' }}>Lithuanian</option>
                    <option value="lb" {{ 'selected' if video.language == 'lb' else '' }}>Luxembourgish</option>
                    <option value="mk" {{ 'selected' if video.language == 'mk' else '' }}>Macedonian</option>
                    <option value="mg" {{ 'selected' if video.language == 'mg' else '' }}>Malagasy</option>
                    <option value="ms" {{ 'selected' if video.language == 'ms' else '' }}>Malay</option>
                    <option value="ml" {{ 'selected' if video.language == 'ml' else '' }}>Malayalam</option>
                    <option value="mt" {{ 'selected' if video.language == 'mt' else '' }}>Maltese</option>
                    <option value="mi" {{ 'selected' if video.language == 'mi' else '' }}>Maori</option>
                    <option value="mr" {{ 'selected' if video.language == 'mr' else '' }}>Marathi</option>
                    <option value="mn" {{ 'selected' if video.language == 'mn' else '' }}>Mongolian</option>
                    <option value="ne" {{ 'selected' if video.language == 'ne' else '' }}>Nepali</option>
                    <option value="no" {{ 'selected' if video.language == 'no' else '' }}>Norwegian</option>
                    <option value="ps" {{ 'selected' if video.language == 'ps' else '' }}>Pashto</option>
                    <option value="fa" {{ 'selected' if video.language == 'fa' else '' }}>Persian</option>
                    <option value="pl" {{ 'selected' if video.language == 'pl' else '' }}>Polish</option>
                    <option value="pt" {{ 'selected' if video.language == 'pt' else '' }}>Portuguese</option>
                    <option value="pa" {{ 'selected' if video.language == 'pa' else '' }}>Punjabi</option>
                    <option value="ro" {{ 'selected' if video.language == 'ro' else '' }}>Romanian</option>
                    <option value="ru" {{ 'selected' if video.language == 'ru' else '' }}>Russian</option>
                    <option value="sm" {{ 'selected' if video.language == 'sm' else '' }}>Samoan</option>
                    <option value="gd" {{ 'selected' if video.language == 'gd' else '' }}>Scottish Gaelic</option>
                    <option value="sr" {{ 'selected' if video.language == 'sr' else '' }}>Serbian</option>
                    <option value="sn" {{ 'selected' if video.language == 'sn' else '' }}>Shona</option>
                    <option value="sd" {{ 'selected' if video.language == 'sd' else '' }}>Sindhi</option>
                    <option value="si" {{ 'selected' if video.language == 'si' else '' }}>Sinhala</option>
                    <option value="sk" {{ 'selected' if video.language == 'sk' else '' }}>Slovak</option>
                    <option value="sl" {{ 'selected' if video.language == 'sl' else '' }}>Slovenian</option>
                    <option value="so" {{ 'selected' if video.language == 'so' else '' }}>Somali</option>
                    <option value="es" {{ 'selected' if video.language == 'es' else '' }}>Spanish</option>
                    <option value="su" {{ 'selected' if video.language == 'su' else '' }}>Sundanese</option>
                    <option value="sw" {{ 'selected' if video.language == 'sw' else '' }}>Swahili</option>
                    <option value="sv" {{ 'selected' if video.language == 'sv' else '' }}>Swedish</option>
                    <option value="tl" {{ 'selected' if video.language == 'tl' else '' }}>Tagalog</option>
                    <option value="tg" {{ 'selected' if video.language == 'tg' else '' }}>Tajik</option>
                    <option value="ta" {{ 'selected' if video.language == 'ta' else '' }}>Tamil</option>
                    <option value="tt" {{ 'selected' if video.language == 'tt' else '' }}>Tatar</option>
                    <option value="te" {{ 'selected' if video.language == 'te' else '' }}>Telugu</option>
                    <option value="th" {{ 'selected' if video.language == 'th' else '' }}>Thai</option>
                    <option value="tr" {{ 'selected' if video.language == 'tr' else '' }}>Turkish</option>
                    <option value="tk" {{ 'selected' if video.language == 'tk' else '' }}>Turkmen</option>
                    <option value="uk" {{ 'selected' if video.language == 'uk' else '' }}>Ukrainian</option>
                    <option value="ur" {{ 'selected' if video.language == 'ur' else '' }}>Urdu</option>
                    <option value="ug" {{ 'selected' if video.language == 'ug' else '' }}>Uyghur</option>
                    <option value="uz" {{ 'selected' if video.language == 'uz' else '' }}>Uzbek</option>
                    <option value="vi" {{ 'selected' if video.language == 'vi' else '' }}>Vietnamese</option>
                    <option value="cy" {{ 'selected' if video.language == 'cy' else '' }}>Welsh</option>
                    <option value="xh" {{ 'selected' if video.language == 'xh' else '' }}>Xhosa</option>
                    <option value="yi" {{ 'selected' if video.language == 'yi' else '' }}>Yiddish</option>
                    <option value="yo" {{ 'selected' if video.language == 'yo' else '' }}>Yoruba</option>
                    <option value="zu" {{ 'selected' if video.language == 'zu' else '' }}>Zulu</option>
                </select>
            </div>
            <div class="form-group">
                <label for="visibility">Visibility</label>
                <select id="visibility" name="visibility">
                    <option value="public" {{ 'selected' if video.visibility == 'public' else '' }}>Public</option>
                    <option value="private" {{ 'selected' if video.visibility == 'private' else '' }}>Private</option>
                </select>
            </div>
            {% if is_admin and eligible_owners %}
            <div class="form-group admin-section">
                <label for="owner_username">Owner (Admin only)</label>
                <select id="owner_username" name="owner_username">
                    {% for user in eligible_owners %}
                    <option value="{{ user.username }}" {{ 'selected' if video.owner_username == user.username else '' }}>{{ user.username }} ({{ user.role }})</option>
                    {% endfor %}
                </select>
            </div>
            {% endif %}
            <button type="submit" class="btn-submit">Save Changes</button>
        </form>

        <footer>RTube v{{ rtube_version }}</footer>
    </body>
</html>
