{% extends 'base.html' %}
{% load static %}

{% block title %}{{ video.title }} | LIVE VERSE{% endblock %}

{% block content %}
<div class="container-fluid px-0 px-lg-4">
    <div class="row g-4">
        <!-- Main Video Area -->
        <div class="col-xl-8">
            <!-- Video Player Placeholder -->
            <div class="ratio ratio-16x9 bg-black rounded-4 overflow-hidden border border-secondary shadow-lg mb-4" style="border-color: var(--lv-border) !important;">
                {% if video.video_file %}
                    <video controls class="w-100 h-100">
                        <source src="{{ video.video_file.url }}" type="video/mp4">
                        Your browser does not support the video tag.
                    </video>
                {% else %}
                    <div class="d-flex flex-column align-items-center justify-content-center text-center">
                        <i class="fas fa-satellite fa-5x mb-3 text-danger opacity-25"></i>
                        <h3 class="fw-bold">Establishing Intergalactic Link...</h3>
                        <p class="text-muted">Wait for the signal to stabilize.</p>
                    </div>
                {% endif %}
            </div>

            <div class="video-info-box p-3">
                <h1 class="h3 fw-bold mb-3">{{ video.title }}</h1>
                
                <div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-4 border-bottom border-secondary pb-4">
                    <div class="d-flex align-items-center gap-3">
                        <div class="rounded-circle bg-gradient d-flex align-items-center justify-content-center" style="width: 48px; height: 48px; background: var(--gradient-cosmic);">
                            <i class="fas fa-user-astronaut text-white"></i>
                        </div>
                        <div>
                            <div class="fw-bold fs-5">{{ video.channel.name }}</div>
                            <div class="text-muted x-small">452K Subscribers</div>
                        </div>
                        <button class="btn btn-danger rounded-pill px-4 ms-2 fw-bold">Subscribe</button>
                    </div>
                    
                    <div class="d-flex gap-2">
                        <button class="action-btn"><i class="far fa-thumbs-up"></i> 12K</button>
                        <button class="action-btn"><i class="fas fa-share-nodes"></i> Share</button>
                        <button class="action-btn"><i class="fas fa-download"></i> Save</button>
                        <button class="action-btn"><i class="fas fa-ellipsis-h"></i></button>
                    </div>
                </div>

                <div class="description-card p-4 rounded-4" style="background: rgba(255,255,255,0.03); border: 1px solid var(--lv-border);">
                    <div class="fw-bold mb-2">{{ video.views }} views • {{ video.created_at|date:"M d, Y" }}</div>
                    <p class="mb-0 text-muted" style="white-space: pre-line;">{{ video.description|default:"No cosmic log provided for this transmission." }}</p>
                </div>
            </div>
        </div>

        <!-- Sidebar / Related Content -->
        <div class="col-xl-4">
            <h5 class="fw-bold mb-3 px-2">Next in Orbit</h5>
            <div class="related-list">
                {% for related in related_videos %}
                <div class="d-flex gap-3 mb-3 p-2 rounded-3 hover-effect" onclick="location.href='{% url 'video_detail' related.id %}'" style="cursor: pointer;">
                    <div class="flex-shrink-0" style="width: 160px; height: 90px;">
                        <img src="{{ related.thumbnail.url }}" class="w-100 h-100 object-fit-cover rounded-3 border border-secondary">
                    </div>
                    <div class="flex-grow-1">
                        <h6 class="fw-bold mb-1 line-clamp-2 small">{{ related.title }}</h6>
                        <div class="text-muted x-small">{{ related.channel.name }}</div>
                        <div class="text-muted x-small">{{ related.views }} views • {{ related.created_at|timesince }} ago</div>
                    </div>
                </div>
                {% empty %}
                <p class="text-muted px-2">No other cosmic events detected nearby.</p>
                {% endfor %}
            </div>
        </div>
    </div>
</div>

<style>
    .hover-effect:hover {
        background: rgba(255, 59, 59, 0.05);
    }
    .line-clamp-2 {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .x-small { font-size: 0.75rem; }
</style>
{% endblock %}
