{% extends 'layouts/base.html' %}
{% load i18n static %}

{% block title %}{{ presentation.title }} — PX360{% endblock %}

{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/presentations/slide-theme.css' %}">
<style>
    .slide-thumb {
        aspect-ratio: 16/9;
        border: 2px solid #e2e8f0;
        border-radius: 12px;
        overflow: hidden;
        transition: all 0.2s ease;
        cursor: pointer;
        position: relative;
    }
    .slide-thumb:hover {
        border-color: #005696;
        transform: translateY(-2px);
        box-shadow: 0 8px 24px rgba(0, 86, 150, 0.1);
    }
    .slide-thumb__number {
        position: absolute;
        top: 8px;
        left: 8px;
        background: rgba(0, 86, 150, 0.9);
        color: white;
        font-size: 11px;
        font-weight: 700;
        width: 24px;
        height: 24px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .slide-thumb__actions {
        position: absolute;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        opacity: 0;
        transition: opacity 0.2s;
    }
    .slide-thumb:hover .slide-thumb__actions {
        opacity: 1;
    }
    .slide-thumb__btn {
        background: white;
        border: none;
        padding: 6px 12px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        cursor: pointer;
        color: #1e293b;
        transition: background 0.2s;
    }
    .slide-thumb__btn:hover {
        background: #eef6fb;
    }
    .slide-thumb__btn--danger {
        color: #ef4444;
    }
    .slide-thumb__preview {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        color: #64748b;
        background: linear-gradient(135deg, #f8fafc, #f1f5f9);
        padding: 8px;
        text-align: center;
    }
</style>
{% endblock %}

{% block content %}
<div class="max-w-7xl mx-auto">
    <div class="flex items-center justify-between mb-6">
        <div>
            <nav class="flex items-center gap-2 text-sm text-gray-400 mb-2">
                <a href="{% url 'presentations:list' %}" class="hover:text-navy transition">{% trans "Presentations" %}</a>
                <i data-lucide="chevron-right" class="w-4 h-4"></i>
                <span class="text-gray-700">{{ presentation.title }}</span>
            </nav>
            <h1 class="text-2xl font-bold text-gray-800">{{ presentation.title }}</h1>
            {% if presentation.subtitle %}
            <p class="text-sm text-gray-500 mt-1">{{ presentation.subtitle }}</p>
            {% endif %}
        </div>
        <div class="flex items-center gap-3">
            {% if slides.exists %}
            <a href="{% url 'presentations:present' pk=presentation.pk %}" target="_blank"
               class="bg-navy text-white px-5 py-2.5 rounded-xl hover:bg-navy/90 transition flex items-center gap-2 font-medium text-sm">
                <i data-lucide="play" class="w-4 h-4"></i>
                {% trans "Present" %}
            </a>
            {% endif %}
            <a href="{% url 'presentations:export_pdf' pk=presentation.pk %}"
               class="bg-white border-2 border-gray-200 text-gray-700 px-4 py-2.5 rounded-xl hover:border-navy hover:text-navy transition flex items-center gap-2 font-medium text-sm">
                <i data-lucide="file-down" class="w-4 h-4"></i>
                {% trans "PDF" %}
            </a>
            <a href="{% url 'presentations:export_pptx' pk=presentation.pk %}"
               class="bg-white border-2 border-gray-200 text-gray-700 px-4 py-2.5 rounded-xl hover:border-navy hover:text-navy transition flex items-center gap-2 font-medium text-sm">
                <i data-lucide="presentation" class="w-4 h-4"></i>
                {% trans "PPTX" %}
            </a>
            <a href="{% url 'presentations:edit' pk=presentation.pk %}"
               class="bg-white border-2 border-gray-200 text-gray-700 px-4 py-2.5 rounded-xl hover:border-navy hover:text-navy transition flex items-center gap-2 font-medium text-sm">
                <i data-lucide="settings" class="w-4 h-4"></i>
                {% trans "Settings" %}
            </a>
        </div>
    </div>

    <div class="bg-white rounded-2xl border-2 border-gray-200 p-6 mb-6">
        <div class="grid grid-cols-2 md:grid-cols-5 gap-4">
            <div>
                <div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-1">{% trans "Status" %}</div>
                <span class="px-2.5 py-1 rounded-full text-xs font-semibold
                    {% if presentation.status == 'published' %}bg-green-50 text-green-700
                    {% elif presentation.status == 'draft' %}bg-amber-50 text-amber-700
                    {% else %}bg-gray-50 text-gray-500{% endif %}">
                    {{ presentation.get_status_display }}
                </span>
            </div>
            <div>
                <div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-1">{% trans "Theme" %}</div>
                <div class="text-sm font-medium text-gray-700">{{ presentation.get_theme_display }}</div>
            </div>
            <div>
                <div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-1">{% trans "Slides" %}</div>
                <div class="text-sm font-medium text-gray-700">{{ slides.count }}</div>
            </div>
            <div>
                <div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-1">{% trans "Created" %}</div>
                <div class="text-sm font-medium text-gray-700">{{ presentation.created_at|date:"M d, Y" }}</div>
            </div>
            <div>
                <div class="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-1">{% trans "Hospital" %}</div>
                <div class="text-sm font-medium text-gray-700">{{ presentation.hospital.name|default:"—" }}</div>
            </div>
        </div>
    </div>

    <div class="flex items-center justify-between mb-4">
        <h2 class="text-lg font-bold text-gray-800">{% trans "Slides" %}</h2>
        <a href="{% url 'presentations:slide_add' pk=presentation.pk %}"
           class="bg-navy/10 text-navy px-4 py-2 rounded-lg hover:bg-navy/20 transition flex items-center gap-2 font-medium text-sm">
            <i data-lucide="plus" class="w-4 h-4"></i>
            {% trans "Add Slide" %}
        </a>
    </div>

    {% if slides.exists %}
    <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
        {% for slide in slides %}
        <div class="slide-thumb" data-slide-id="{{ slide.id }}">
            <div class="slide-thumb__number">{{ slide.order }}</div>
            <div class="slide-thumb__preview">
                <div>
                    <div class="font-semibold text-gray-600 text-xs mb-1">{{ slide.get_layout_display }}</div>
                    {% if slide.title %}<div>{{ slide.title|truncatewords:6 }}</div>{% endif %}
                </div>
            </div>
            <div class="slide-thumb__actions">
                <a href="{% url 'presentations:slide_edit' pk=presentation.pk slide_id=slide.id %}" class="slide-thumb__btn">{% trans "Edit" %}</a>
                <form method="post" action="{% url 'presentations:slide_delete' pk=presentation.pk slide_id=slide.id %}" style="display:inline;" onsubmit="return confirm('{% trans 'Delete this slide?' %}')">
                    {% csrf_token %}
                    <button type="submit" class="slide-thumb__btn slide-thumb__btn--danger">{% trans "Delete" %}</button>
                </form>
            </div>
        </div>
        {% endfor %}
    </div>
    {% else %}
    <div class="bg-white rounded-2xl border-2 border-dashed border-gray-300 p-12 text-center">
        <i data-lucide="layers" class="w-12 h-12 text-gray-300 mx-auto mb-4"></i>
        <h3 class="text-lg font-semibold text-gray-700 mb-2">{% trans "No slides yet" %}</h3>
        <p class="text-gray-500 mb-4">{% trans "Add your first slide to get started." %}</p>
        <a href="{% url 'presentations:slide_add' pk=presentation.pk %}"
           class="bg-navy text-white px-5 py-2.5 rounded-xl hover:bg-navy/90 transition inline-flex items-center gap-2 font-medium text-sm">
            <i data-lucide="plus" class="w-4 h-4"></i>
            {% trans "Add Slide" %}
        </a>
    </div>
    {% endif %}
</div>
{% endblock %}
