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

{% block title %}{% trans "Manage Acknowledgements" %} - 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;
}
</style>
{% endblock %}

{% block content %}
<div class="p-6 md:p-8 bg-gradient-to-br from-light to-blue-50 min-h-screen">
    <!-- Page Header -->
    <div class="page-header-gradient">
        <div class="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
            <div class="flex items-center gap-3">
                <div class="section-icon bg-white/20">
                    <i data-lucide="clipboard-list" class="w-6 h-6 text-white"></i>
                </div>
                <div>
                    <h1 class="text-2xl font-bold">{% trans "Acknowledgements" %}</h1>
                    <p class="text-white/80 text-sm">{% trans "Manage employee acknowledgement forms" %}</p>
                </div>
            </div>
            <div class="flex gap-3">
                <a href="{% url 'accounts:simple_acknowledgements:admin_signatures' %}"
                   class="inline-flex items-center gap-2 px-5 py-2.5 bg-white/20 border border-white/30 text-white rounded-xl font-semibold hover:bg-white/30 transition">
                    <i data-lucide="users" class="w-4 h-4"></i>
                    {% trans "View Signatures" %}
                </a>
                <a href="{% url 'accounts:simple_acknowledgements:admin_create' %}"
                   class="inline-flex items-center gap-2 px-5 py-2.5 bg-white text-emerald-700 rounded-xl font-semibold hover:bg-emerald-50 transition shadow-lg">
                    <i data-lucide="plus" class="w-4 h-4"></i>
                    {% trans "New Acknowledgement" %}
                </a>
            </div>
        </div>
    </div>

    <!-- Stats Cards -->
    <div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
        <div class="section-card p-5">
            <div class="flex items-center gap-3">
                <div class="section-icon bg-blue-100">
                    <i data-lucide="clipboard" class="w-5 h-5 text-blue-600"></i>
                </div>
                <div>
                    <p class="text-xs text-slate uppercase font-semibold">{% trans "Total" %}</p>
                    <p class="text-2xl font-bold text-navy">{{ acknowledgements|length }}</p>
                </div>
            </div>
        </div>
        <div class="section-card p-5 border-emerald-200">
            <div class="flex items-center gap-3">
                <div class="section-icon bg-emerald-100">
                    <i data-lucide="check-circle" class="w-5 h-5 text-emerald-600"></i>
                </div>
                <div>
                    <p class="text-xs text-slate uppercase font-semibold">{% trans "Active" %}</p>
                    <p class="text-2xl font-bold text-emerald-600">{{ acknowledgements|length }}</p>
                </div>
            </div>
        </div>
    </div>

    <!-- Acknowledgements Table -->
    <div class="section-card">
        <div class="section-header">
            <div class="section-icon bg-blue-100">
                <i data-lucide="list" class="w-5 h-5 text-blue-600"></i>
            </div>
            <h2 class="text-lg font-bold text-navy">{% trans "All Acknowledgements" %}</h2>
        </div>
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead class="bg-slate-50">
                    <tr>
                        <th class="px-6 py-3 text-left text-xs font-bold text-slate uppercase tracking-wider">{% trans "Title" %}</th>
                        <th class="px-6 py-3 text-left text-xs font-bold text-slate uppercase tracking-wider">{% trans "Status" %}</th>
                        <th class="px-6 py-3 text-center text-xs font-bold text-slate uppercase tracking-wider">{% trans "Signed" %}</th>
                        <th class="px-6 py-3 text-left text-xs font-bold text-slate uppercase tracking-wider">{% trans "PDF" %}</th>
                        <th class="px-6 py-3 text-right text-xs font-bold text-slate uppercase tracking-wider">{% trans "Actions" %}</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-100">
                    {% for ack in acknowledgements %}
                    <tr class="hover:bg-slate-50 transition">
                        <td class="px-6 py-4">
                            <div class="font-semibold text-navy">{{ ack.title }}</div>
                            {% if ack.description %}
                                <div class="text-sm text-slate mt-1">{{ ack.description|truncatewords:10 }}</div>
                            {% endif %}
                        </td>
                        <td class="px-6 py-4">
                            {% if ack.is_active %}
                                <span class="inline-flex items-center px-2.5 py-1 bg-emerald-100 text-emerald-700 rounded-lg text-xs font-bold">
                                    {% trans "Active" %}
                                </span>
                            {% else %}
                                <span class="inline-flex items-center px-2.5 py-1 bg-slate-100 text-slate-600 rounded-lg text-xs font-bold">
                                    {% trans "Inactive" %}
                                </span>
                            {% endif %}
                            {% if ack.is_required %}
                                <span class="inline-flex items-center px-2.5 py-1 bg-red-100 text-red-700 rounded-lg text-xs font-bold ml-1">
                                    {% trans "Required" %}
                                </span>
                            {% endif %}
                        </td>
                        <td class="px-6 py-4 text-center">
                            <span class="inline-flex items-center gap-1 px-3 py-1 bg-blue-50 text-blue rounded-lg text-sm font-semibold">
                                <i data-lucide="users" class="w-4 h-4"></i>
                                {{ ack.signed_count }}
                            </span>
                        </td>
                        <td class="px-6 py-4">
                            {% if ack.pdf_document %}
                                <a href="{{ ack.pdf_document.url }}" target="_blank"
                                   class="inline-flex items-center gap-1 text-blue hover:text-navy transition">
                                    <i data-lucide="file-text" class="w-4 h-4"></i>
                                    <span class="text-sm">{% trans "View" %}</span>
                                </a>
                            {% else %}
                                <span class="text-slate text-sm">-</span>
                            {% endif %}
                        </td>
                        <td class="px-6 py-4 text-right">
                            <div class="flex items-center justify-end gap-2">
                                <a href="{% url 'accounts:simple_acknowledgements:admin_send' ack.id %}"
                                   class="inline-flex items-center gap-1 px-3 py-1.5 bg-purple-50 text-purple-600 rounded-lg text-sm font-semibold hover:bg-purple-100 transition"
                                   title="{% trans 'Send to Staff' %}">
                                    <i data-lucide="send" class="w-4 h-4"></i>
                                    {% trans "Send" %}
                                </a>
                                <a href="{% url 'accounts:simple_acknowledgements:admin_edit' ack.id %}"
                                   class="inline-flex items-center gap-1 px-3 py-1.5 bg-blue-50 text-blue rounded-lg text-sm font-semibold hover:bg-blue-100 transition">
                                    <i data-lucide="edit" class="w-4 h-4"></i>
                                    {% trans "Edit" %}
                                </a>
                                <a href="{% url 'accounts:simple_acknowledgements:admin_delete' ack.id %}"
                                   class="inline-flex items-center gap-1 px-3 py-1.5 bg-red-50 text-red-600 rounded-lg text-sm font-semibold hover:bg-red-100 transition">
                                    <i data-lucide="trash-2" class="w-4 h-4"></i>
                                    {% trans "Delete" %}
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="5" class="px-6 py-12 text-center text-slate">
                            <div class="flex flex-col items-center gap-3">
                                <i data-lucide="clipboard-x" class="w-12 h-12 text-slate-300"></i>
                                <p class="font-medium">{% trans "No acknowledgements created yet" %}</p>
                                <a href="{% url 'accounts:simple_acknowledgements:admin_create' %}"
                                   class="inline-flex items-center gap-2 px-4 py-2 bg-blue text-white rounded-lg font-semibold hover:bg-navy transition">
                                    <i data-lucide="plus" class="w-4 h-4"></i>
                                    {% trans "Create First Acknowledgement" %}
                                </a>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

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