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

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

{% block content %}
<div class="container-fluid px-4">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0">{% trans "Reference Section" %}</h1>
            <p class="text-muted small mb-0">{% trans "Access and manage reference documents" %}</p>
        </div>
        <div class="d-flex gap-2">
            <a href="{% url 'references:search' %}" class="btn btn-outline-primary">
                <i class="fas fa-search me-2"></i>{% trans "Search" %}
            </a>
            <a href="{% url 'references:folder_create' %}" class="btn btn-primary">
                <i class="fas fa-folder-plus me-2"></i>{% trans "New Folder" %}
            </a>
            <a href="{% url 'references:document_create' %}" class="btn btn-success">
                <i class="fas fa-upload me-2"></i>{% trans "Upload Document" %}
            </a>
        </div>
    </div>

    <!-- Statistics Cards -->
    <div class="row mb-4">
        <div class="col-md-6">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-shrink-0">
                            <div class="bg-primary bg-opacity-10 rounded-3 p-3">
                                <i class="fas fa-folder text-primary fa-2x"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="text-muted mb-1">{% trans "Total Folders" %}</h6>
                            <h2 class="mb-0">{{ total_folders }}</h2>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-shrink-0">
                            <div class="bg-success bg-opacity-10 rounded-3 p-3">
                                <i class="fas fa-file-alt text-success fa-2x"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="text-muted mb-1">{% trans "Total Documents" %}</h6>
                            <h2 class="mb-0">{{ total_documents }}</h2>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <!-- Folders -->
        <div class="col-lg-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">{% trans "Folders" %}</h5>
                </div>
                <div class="card-body">
                    {% if folders %}
                        <div class="row">
                            {% for folder in folders %}
                                <div class="col-md-6 col-lg-4 mb-3">
                                    <a href="{% url 'references:folder_view' folder.id %}" class="card h-100 text-decoration-none text-dark folder-card">
                                        <div class="card-body">
                                            <div class="d-flex align-items-center mb-2">
                                                <div class="flex-shrink-0">
                                                    {% if folder.icon %}
                                                        <i class="{{ folder.icon }} fa-2x text-primary"></i>
                                                    {% else %}
                                                        <i class="fas fa-folder fa-2x text-primary"></i>
                                                    {% endif %}
                                                </div>
                                                <div class="flex-grow-1 ms-3">
                                                    <h6 class="mb-0">{{ folder.name }}</h6>
                                                    <small class="text-muted">{{ folder.document_count }} {% trans "documents" %}</small>
                                                </div>
                                            </div>
                                            {% if folder.description %}
                                                <p class="small text-muted mb-0">{{ folder.description|truncatewords:10 }}</p>
                                            {% endif %}
                                        </div>
                                    </a>
                                </div>
                            {% empty %}
                                <p class="text-muted text-center py-5">
                                    <i class="fas fa-folder-open fa-3x mb-3 d-block text-muted"></i>
                                    {% trans "No folders yet. Create your first folder to get started." %}
                                </p>
                            {% endfor %}
                        </div>
                    {% else %}
                        <div class="text-center py-5">
                            <i class="fas fa-folder-open fa-3x mb-3 text-muted"></i>
                            <p class="text-muted mb-3">{% trans "No folders yet" %}</p>
                            <a href="{% url 'references:folder_create' %}" class="btn btn-primary">
                                <i class="fas fa-plus me-2"></i>{% trans "Create Folder" %}
                            </a>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>

        <!-- Recent Documents -->
        <div class="col-lg-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">{% trans "Recent Documents" %}</h5>
                </div>
                <div class="card-body">
                    {% if recent_documents %}
                        <div class="list-group list-group-flush">
                            {% for document in recent_documents %}
                                <a href="{% url 'references:document_view' document.id %}" class="list-group-item list-group-item-action text-decoration-none">
                                    <div class="d-flex align-items-center">
                                        <div class="flex-shrink-0">
                                            <i class="{{ document.get_file_icon }} fa-lg"></i>
                                        </div>
                                        <div class="flex-grow-1 ms-3">
                                            <h6 class="mb-1 small">{{ document.title|truncatechars:40 }}</h6>
                                            <small class="text-muted">{{ document.get_file_size_display }}</small>
                                        </div>
                                    </div>
                                </a>
                            {% endfor %}
                        </div>
                        <a href="{% url 'references:search' %}" class="btn btn-outline-primary btn-sm w-100 mt-3">
                            {% trans "View All Documents" %}
                        </a>
                    {% else %}
                        <p class="text-muted text-center py-4">
                            {% trans "No documents uploaded yet" %}
                        </p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.folder-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
    transition: all 0.2s ease;
}
</style>
{% endblock %}
