{% extends "layouts/base.html" %}
{% load i18n %}

{% block title %}{% trans "Enhanced Survey Reports" %} - PX360{% endblock %}

{% block extra_css %}
<style>
.page-header-gradient {
    background: linear-gradient(135deg, #005696 0%, #0069a8 50%, #007bbd 100%);
    color: white;
    padding: 1.5rem 2rem;
    border-radius: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 86, 150, 0.2);
}

.section-card {
    background: white;
    border-radius: 1rem;
    border: 2px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.3s ease;
}
.section-card:hover {
    border-color: #005696;
    box-shadow: 0 10px 25px -5px rgba(0, 86, 150, 0.15);
}

.section-header {
    padding: 1rem 1.5rem;
    border-bottom: 2px solid #e2e8f0;
    background: linear-gradient(to right, #f8fafc, #f1f5f9);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.section-icon {
    width: 40px;
    height: 40px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feature-card {
    background: white;
    border-radius: 1rem;
    border: 2px solid #e2e8f0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    height: 100%;
    transition: all 0.3s ease;
    text-align: center;
}
.feature-card:hover {
    border-color: #005696;
    box-shadow: 0 10px 25px -5px rgba(0, 86, 150, 0.15);
}

.info-alert {
    background: linear-gradient(to right, #dbeafe, #eff6ff);
    border: 2px solid #bfdbfe;
    border-radius: 1rem;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}
</style>
{% endblock %}

{% block content %}
<!-- Page Header -->
<div class="page-header-gradient">
    <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
        <div>
            <h1 class="text-2xl font-bold flex items-center gap-3">
                <div class="section-icon bg-white/20">
                    <i data-lucide="file-bar-chart" class="w-6 h-6 text-white"></i>
                </div>
                {% trans "Enhanced Survey Reports" %}
            </h1>
            <p class="text-white/80 mt-2">{% trans "Separate detailed reports for each survey type with question-level analysis" %}</p>
        </div>
        <div class="flex items-center gap-3">
            <a href="{% url 'surveys:generate_enhanced_report' %}" class="px-4 py-2.5 bg-white text-[#005696] rounded-xl font-semibold hover:bg-white/90 transition flex items-center gap-2 shadow-lg">
                <i data-lucide="plus" class="w-5 h-5"></i> {% trans "Generate New Reports" %}
            </a>
            <a href="{% url 'surveys:analytics_reports' %}" class="px-4 py-2.5 bg-white/20 text-white rounded-xl font-semibold hover:bg-white/30 transition flex items-center gap-2 border border-white/30">
                <i data-lucide="arrow-left" class="w-5 h-5"></i> {% trans "Back to Standard" %}
            </a>
        </div>
    </div>
</div>

<!-- Info Alert -->
<div class="info-alert">
    <div class="flex items-start gap-3">
        <div class="section-icon bg-blue-100 flex-shrink-0">
            <i data-lucide="info" class="w-5 h-5 text-blue-600"></i>
        </div>
        <div>
            <h5 class="font-bold text-navy mb-1">{% trans "What are Enhanced Reports?" %}</h5>
            <p class="text-slate text-sm mb-0">
                {% trans "Enhanced reports generate a separate HTML file for each survey template with detailed question-level analysis. 
                Each report includes individual charts per question, performance insights, and recommendations. 
                A master index page links all reports together for easy navigation." %}
            </p>
        </div>
    </div>
</div>

<!-- Report Sets Section Card -->
<div class="section-card mb-6">
    <div class="section-header">
        <div class="section-icon bg-purple-100">
            <i data-lucide="folder-open" class="w-5 h-5 text-purple-600"></i>
        </div>
        <h3 class="font-bold text-navy">{% trans "Available Report Sets" %}</h3>
    </div>
    <div class="p-6">
        {% if report_sets %}
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-slate-50 border-b border-slate-100">
                    <tr class="text-xs font-bold text-slate uppercase tracking-wider">
                        <th class="px-6 py-4 text-left">{% trans "Generated" %}</th>
                        <th class="px-6 py-4 text-left">{% trans "Reports Count" %}</th>
                        <th class="px-6 py-4 text-left">{% trans "Total Size" %}</th>
                        <th class="px-6 py-4 text-left">{% trans "Last Modified" %}</th>
                        <th class="px-6 py-4 text-right">{% trans "Actions" %}</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    {% for report_set in report_sets %}
                    <tr class="hover:bg-slate-50 transition">
                        <td class="px-6 py-4">
                            <div class="flex items-center gap-2">
                                <i data-lucide="folder" class="w-5 h-5 text-blue-500"></i>
                                <span class="font-semibold text-navy">{{ report_set.created|date:"Y-m-d H:i" }}</span>
                            </div>
                        </td>
                        <td class="px-6 py-4">
                            <span class="px-2.5 py-1 rounded-lg text-xs font-bold bg-blue-100 text-blue-700">{{ report_set.report_count }} {% trans "reports" %}</span>
                        </td>
                        <td class="px-6 py-4">
                            <span class="text-sm text-slate">{{ report_set.size|filesizeformat }}</span>
                        </td>
                        <td class="px-6 py-4">
                            <span class="text-sm text-slate">{{ report_set.modified|date:"Y-m-d H:i" }}</span>
                        </td>
                        <td class="px-6 py-4 text-right">
                            <a href="{% url 'surveys:enhanced_report_view' report_set.dir_name %}" 
                               class="inline-flex items-center gap-1 px-4 py-2 bg-navy text-white rounded-lg text-sm font-semibold hover:bg-blue transition"
                               target="_blank">
                                <i data-lucide="eye" class="w-4 h-4"></i> {% trans "View Index" %}
                            </a>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% else %}
        <!-- Empty State -->
        <div class="text-center py-12">
            <div class="inline-flex items-center justify-center w-16 h-16 bg-slate-100 rounded-full mb-4">
                <i data-lucide="folder-x" class="w-8 h-8 text-slate-400"></i>
            </div>
            <h5 class="text-lg font-bold text-navy mb-2">{% trans "No enhanced reports found" %}</h5>
            <p class="text-slate mb-4">
                {% trans "Generate your first set of enhanced survey reports with detailed question analysis." %}
            </p>
            <a href="{% url 'surveys:generate_enhanced_report' %}" class="inline-flex items-center gap-2 px-4 py-2.5 bg-navy text-white rounded-xl font-semibold hover:bg-blue transition">
                <i data-lucide="plus" class="w-5 h-5"></i> {% trans "Generate Reports" %}
            </a>
        </div>
        {% endif %}
    </div>
</div>

<!-- Features -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
    <div class="feature-card">
        <div class="section-icon bg-blue-100 mx-auto mb-4">
            <i data-lucide="file-text" class="w-6 h-6 text-blue-600"></i>
        </div>
        <h5 class="font-bold text-navy mb-2">{% trans "Separate Reports" %}</h5>
        <p class="text-slate text-sm mb-0">
            {% trans "Each survey template gets its own dedicated HTML report file with comprehensive analysis." %}
        </p>
    </div>
    <div class="feature-card">
        <div class="section-icon bg-green-100 mx-auto mb-4">
            <i data-lucide="trending-up" class="w-6 h-6 text-green-600"></i>
        </div>
        <h5 class="font-bold text-navy mb-2">{% trans "Question-Level Analysis" %}</h5>
        <p class="text-slate text-sm mb-0">
            {% trans "Detailed charts and metrics for each individual question with score distributions and trends." %}
        </p>
    </div>
    <div class="feature-card">
        <div class="section-icon bg-amber-100 mx-auto mb-4">
            <i data-lucide="lightbulb" class="w-6 h-6 text-amber-600"></i>
        </div>
        <h5 class="font-bold text-navy mb-2">{% trans "Smart Insights" %}</h5>
        <p class="text-slate text-sm mb-0">
            {% trans "Automatic insights and recommendations based on performance metrics and trends." %}
        </p>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
document.addEventListener('DOMContentLoaded', function() {
    lucide.createIcons();
});
</script>
{% endblock %}
