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

{% block title %}{% trans "Reference Section" %} - {% trans "PX360" %}{% endblock %}

{% block extra_css %}
<style>
    /* PX360 App Theme Variables */
    :root {
        --hh-navy: #005696;
        --hh-blue: #007bbd;
        --hh-light: #eef6fb;
        --hh-slate: #64748b;
    }

    /* Page Header */
    .page-header-gradient {
        background: linear-gradient(135deg, var(--hh-navy) 0%, #0069a8 50%, var(--hh-blue) 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 Cards */
    .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;
    }

    /* Stats Cards */
    .stat-card {
        background: white;
        border-radius: 1rem;
        border: 2px solid #e2e8f0;
        padding: 1.5rem;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        transition: all 0.3s ease;
    }
    .stat-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        border-color: #005696;
    }

    /* Folder Cards */
    .folder-card {
        background: white;
        border: 2px solid #e2e8f0;
        border-radius: 0.75rem;
        padding: 1rem;
        transition: all 0.3s ease;
        text-decoration: none;
        color: inherit;
        display: block;
    }
    .folder-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 12px 24px -8px rgba(0, 86, 150, 0.2);
        border-color: #005696;
    }

    /* Document Rows */
    .document-row {
        display: flex;
        align-items: center;
        padding: 1rem;
        transition: all 0.2s ease;
        text-decoration: none;
        color: inherit;
    }
    .document-row:hover {
        background-color: #f8fafc;
    }

    /* Button Transitions */
    .btn-transition {
        transition: all 0.2s ease-in-out;
    }

    /* Empty State */
    .empty-state {
        text-align: center;
        padding: 3rem;
    }
    .empty-state-icon {
        width: 64px;
        height: 64px;
        margin: 0 auto 1rem;
        color: #cbd5e1;
    }
</style>
{% endblock %}

{% block content %}
<div class="px-6 py-4">
    <!-- Page Header -->
    <div class="page-header-gradient">
        <div class="flex justify-between items-center">
            <div>
                <h1 class="text-2xl font-bold mb-1">{% trans "Reference Section" %}</h1>
                <p class="text-blue-100 text-sm">{% trans "Access and manage reference documents" %}</p>
            </div>
            <div class="flex gap-2">
                <a href="{% url 'references:search' %}" class="btn-transition inline-flex items-center px-4 py-2.5 bg-white/10 border-2 border-white/30 text-white font-medium rounded-xl hover:bg-white hover:text-navy transition">
                    <i data-lucide="search" class="w-4 h-4 me-2"></i>{% trans "Search" %}
                </a>
                <a href="{% url 'references:folder_create' %}" class="btn-transition inline-flex items-center px-4 py-2.5 bg-white text-navy font-medium rounded-xl hover:bg-blue-50 transition">
                    <i data-lucide="folder-plus" class="w-4 h-4 me-2"></i>{% trans "New Folder" %}
                </a>
                <a href="{% url 'references:document_create' %}" class="btn-transition inline-flex items-center px-4 py-2.5 bg-green-500 text-white font-medium rounded-xl hover:bg-green-600 transition">
                    <i data-lucide="upload" class="w-4 h-4 me-2"></i>{% trans "Upload" %}
                </a>
            </div>
        </div>
    </div>

    <!-- Statistics Cards -->
    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
        <div class="stat-card">
            <div class="flex items-center">
                <div class="flex-shrink-0">
                    <div class="w-14 h-14 bg-navy/10 rounded-xl flex items-center justify-center">
                        <i data-lucide="folder" class="w-7 h-7 text-navy"></i>
                    </div>
                </div>
                <div class="ml-4">
                    <h6 class="text-slate-500 text-sm font-medium mb-1">{% trans "Total Folders" %}</h6>
                    <h2 class="text-3xl font-bold text-gray-800">{{ total_folders }}</h2>
                </div>
            </div>
        </div>
        <div class="stat-card">
            <div class="flex items-center">
                <div class="flex-shrink-0">
                    <div class="w-14 h-14 bg-green-500/10 rounded-xl flex items-center justify-center">
                        <i data-lucide="file-text" class="w-7 h-7 text-green-600"></i>
                    </div>
                </div>
                <div class="ml-4">
                    <h6 class="text-slate-500 text-sm font-medium mb-1">{% trans "Total Documents" %}</h6>
                    <h2 class="text-3xl font-bold text-gray-800">{{ total_documents }}</h2>
                </div>
            </div>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <!-- Folders -->
        <div class="lg:col-span-2">
            <div class="section-card">
                <div class="section-header">
                    <div class="section-icon bg-navy/10">
                        <i data-lucide="folder" class="w-5 h-5 text-navy"></i>
                    </div>
                    <h5 class="text-lg font-semibold text-gray-800">{% trans "Folders" %}</h5>
                </div>
                <div class="p-4">
                    {% if folders %}
                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                            {% for folder in folders %}
                                <a href="{% url 'references:folder_view' folder.id %}" class="folder-card">
                                    <div class="flex items-center mb-2">
                                        <div class="flex-shrink-0">
                                            {% if folder.icon %}
                                                <i class="{{ folder.icon }} w-8 h-8 text-navy"></i>
                                            {% else %}
                                                <i data-lucide="folder" class="w-8 h-8 text-navy"></i>
                                            {% endif %}
                                        </div>
                                        <div class="ml-3">
                                            <h6 class="font-semibold text-gray-800 text-sm">{{ folder.name }}</h6>
                                            <small class="text-slate-500 text-xs">{{ folder.document_count }} {% trans "documents" %}</small>
                                        </div>
                                    </div>
                                    {% if folder.description %}
                                        <p class="text-slate-500 text-xs">{{ folder.description|truncatewords:8 }}</p>
                                    {% endif %}
                                </a>
                            {% endfor %}
                        </div>
                    {% else %}
                        <div class="empty-state">
                            <i data-lucide="folder-open" class="empty-state-icon"></i>
                            <p class="text-slate-500 mb-4">{% trans "No folders yet. Create your first folder to get started." %}</p>
                            <a href="{% url 'references:folder_create' %}" class="btn-transition inline-flex items-center px-4 py-2 bg-navy text-white font-medium rounded-lg hover:bg-blue transition">
                                <i data-lucide="plus" class="w-4 h-4 me-2"></i>{% trans "Create Folder" %}
                            </a>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>

        <!-- Recent Documents -->
        <div class="lg:col-span-1">
            <div class="section-card">
                <div class="section-header">
                    <div class="section-icon bg-blue/10">
                        <i data-lucide="file-clock" class="w-5 h-5 text-blue"></i>
                    </div>
                    <h5 class="text-lg font-semibold text-gray-800">{% trans "Recent Documents" %}</h5>
                </div>
                <div class="p-0">
                    {% if recent_documents %}
                        <div class="divide-y divide-gray-100">
                            {% for document in recent_documents %}
                                <a href="{% url 'references:document_view' document.id %}" class="document-row">
                                    <div class="flex-shrink-0">
                                        <i class="{{ document.get_file_icon }} w-8 h-8 text-blue"></i>
                                    </div>
                                    <div class="ml-3 flex-1 min-w-0">
                                        <h6 class="font-medium text-gray-800 text-sm truncate">{{ document.title|truncatechars:35 }}</h6>
                                        <small class="text-slate-500 text-xs">{{ document.get_file_size_display }}</small>
                                    </div>
                                </a>
                            {% endfor %}
                        </div>
                        <div class="p-4 border-t border-gray-100">
                            <a href="{% url 'references:search' %}" class="btn-transition w-full inline-flex justify-center items-center px-4 py-2 bg-white border-2 border-navy text-navy font-medium rounded-lg hover:bg-navy hover:text-white transition text-sm">
                                {% trans "View All Documents" %}
                            </a>
                        </div>
                    {% else %}
                        <div class="empty-state">
                            <i data-lucide="file-text" class="w-12 h-12 mx-auto mb-3 text-slate-300"></i>
                            <p class="text-slate-500 text-sm">{% trans "No documents uploaded yet" %}</p>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
