{% extends "base.html" %}

{% block content %}
<div class="container-fluid py-5 px-lg-5">
    <!-- Header/Dashboard Info -->
    <div class="row align-items-center mb-5">
        <div class="col-lg-6">
            <h1 class="display-3 text-cyan font-syncopate mb-0">STUDIO COMMAND CENTER</h1>
            <p class="lead text-purple fw-bold mb-4">Gerenciamento de Super-Produções CGI</p>
        </div>
        <div class="col-lg-6 text-lg-end">
            <div class="d-inline-block p-3 glass-effect border-cyan rounded-3 text-center me-3">
                <span class="d-block text-secondary small">Projetos Ativos</span>
                <span class="h2 text-white mb-0">{{ active_productions }}</span>
            </div>
            <div class="d-inline-block p-3 glass-effect border-purple rounded-3 text-center">
                <span class="d-block text-secondary small">Status do Sistema</span>
                <span class="h2 text-cyan mb-0">ONLINE</span>
            </div>
        </div>
    </div>

    <!-- Navigation / Quick Actions -->
    <div class="row mb-5">
        <div class="col-12">
            <div class="glass-effect p-3 border-secondary rounded-3 d-flex justify-content-between align-items-center">
                <div class="d-flex gap-3">
                    <a href="{% url 'asset_library' %}" class="btn btn-outline-purple shadow-neon">
                        <i class="bi bi-box-seam me-2"></i> Biblioteca de Assets
                    </a>
                    <a href="{% url 'studio_ai' %}" class="btn btn-neon-purple">
                        <i class="bi bi-magic me-2"></i> STUDIO AI (Criador Automático)
                    </a>
                </div>
                <div>
                    {% if is_admin %}
                    <span class="badge bg-purple p-2 me-2"><i class="bi bi-person-check-fill"></i> MODO ADMIN</span>
                    <a href="{% url 'admin_logout' %}" class="btn btn-sm btn-outline-danger">Sair</a>
                    {% else %}
                    <a href="{% url 'admin_login' %}" class="text-secondary small text-decoration-none">
                        <i class="bi bi-lock"></i> Acesso Restrito
                    </a>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <!-- Main Grid -->
    <div class="row g-4">
        {% for project in projects %}
        <div class="col-lg-6">
            <div class="card bg-dark border-secondary h-100 glass-effect overflow-hidden hover-border-cyan">
                <div class="row g-0">
                    <div class="col-md-4 bg-secondary d-flex align-items-center justify-content-center" style="min-height: 200px; background: linear-gradient(45deg, #0a0a0c, #121214);">
                        {% if project.thumbnail_url %}
                            <img src="{{ project.thumbnail_url }}" alt="{{ project.title }}" class="img-fluid object-fit-cover h-100">
                        {% else %}
                            <div class="text-center">
                                <i class="bi bi-camera-reels text-purple display-1"></i>
                                {% if project.is_ai_generated %}
                                <div class="mt-2"><span class="badge bg-purple small">AI GENERATED</span></div>
                                {% endif %}
                            </div>
                        {% endif %}
                    </div>
                    <div class="col-md-8">
                        <div class="card-body p-4">
                            <div class="d-flex justify-content-between align-items-start mb-2">
                                <h3 class="card-title text-white font-syncopate h4 mb-0">{{ project.title }}</h3>
                                <div class="text-end">
                                    <span class="badge {% if project.status == 'PROD' %}bg-cyan text-dark{% else %}bg-purple{% endif %} d-block mb-1">
                                        {{ project.get_status_display }}
                                    </span>
                                    <span class="badge bg-dark border border-secondary small">{{ project.category }}</span>
                                </div>
                            </div>
                            <p class="text-secondary small mb-4">{{ project.description|truncatewords:20 }}</p>
                            
                            <!-- Pipeline Progress Mini -->
                            <div class="mb-4">
                                <div class="d-flex justify-content-between small text-secondary mb-1">
                                    <span>Status Pipeline</span>
                                    <span>{% with last=project.steps.last %}{{ last.progress|default:0 }}{% endwith %}%</span>
                                </div>
                                <div class="progress bg-black" style="height: 6px;">
                                    <div class="progress-bar bg-cyan shadow-neon" role="progressbar" style="width: {% with last=project.steps.last %}{{ last.progress|default:0 }}{% endwith %}%;"></div>
                                </div>
                            </div>

                            <a href="{% url 'project_detail' project.slug %}" class="btn btn-link text-cyan p-0 text-decoration-none">
                                Ver Pipeline Detalhado <i class="bi bi-arrow-right ms-1"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</div>

<style>
    .hover-border-cyan:hover {
        border-color: var(--electric-cyan) !important;
        transition: 0.3s ease;
    }
    .bg-cyan { background-color: var(--electric-cyan) !important; }
</style>
{% endblock %}