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

{% block title %}{% trans "My Acknowledgements" %} - PX360{% 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="flex flex-col md:flex-row justify-between items-start md:items-center gap-4 mb-8">
        <div class="flex items-center gap-3">
            <div class="flex items-center justify-center w-14 h-14 bg-gradient-to-br from-blue to-indigo-500 rounded-2xl shadow-lg shadow-blue-200">
                <i data-lucide="clipboard-check" class="w-8 h-8 text-white"></i>
            </div>
            <div>
                <h1 class="text-2xl font-bold text-navy">
                    {% trans "My Acknowledgements" %}
                </h1>
                <p class="text-slate text-sm">
                    {% trans "Review and sign required acknowledgements" %}
                </p>
            </div>
        </div>
        <div class="flex gap-3">
            <a href="{% url 'accounts:acknowledgements:ack_signed_list' %}" class="inline-flex items-center gap-2 px-5 py-2.5 bg-white border-2 border-emerald-200 text-emerald-700 rounded-xl font-semibold hover:bg-emerald-50 transition">
                <i data-lucide="check-circle" class="w-4 h-4"></i>
                {% trans "Completed" %}
            </a>
        </div>
    </div>

    <!-- Stats Cards -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
        <div class="bg-white rounded-2xl shadow-sm border border-blue-100 p-6">
            <div class="flex items-center gap-3">
                <div class="w-12 h-12 bg-gradient-to-br from-blue to-navy rounded-xl flex items-center justify-center">
                    <i data-lucide="list" class="w-6 h-6 text-white"></i>
                </div>
                <div>
                    <p class="text-xs font-semibold text-slate uppercase">{% trans "Total" %}</p>
                    <p class="text-3xl font-bold text-navy">{{ total_count }}</p>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-2xl shadow-sm border border-orange-100 p-6">
            <div class="flex items-center gap-3">
                <div class="w-12 h-12 bg-gradient-to-br from-orange-400 to-orange-500 rounded-xl flex items-center justify-center">
                    <i data-lucide="clock" class="w-6 h-6 text-white"></i>
                </div>
                <div>
                    <p class="text-xs font-semibold text-slate uppercase">{% trans "Pending" %}</p>
                    <p class="text-3xl font-bold text-orange-600">{{ pending_count }}</p>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-2xl shadow-sm border border-emerald-100 p-6">
            <div class="flex items-center gap-3">
                <div class="w-12 h-12 bg-gradient-to-br from-emerald-500 to-green-500 rounded-xl flex items-center justify-center">
                    <i data-lucide="check-circle" class="w-6 h-6 text-white"></i>
                </div>
                <div>
                    <p class="text-xs font-semibold text-slate uppercase">{% trans "Completed" %}</p>
                    <p class="text-3xl font-bold text-emerald-600">{{ completed_count }}</p>
                </div>
            </div>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
        <!-- Pending Acknowledgements -->
        <div class="bg-white rounded-2xl shadow-sm border border-orange-100 overflow-hidden">
            <div class="px-6 py-5 border-b border-orange-100 bg-gradient-to-r from-orange-50 to-transparent">
                <h2 class="text-lg font-bold text-navy flex items-center gap-2">
                    <i data-lucide="clock" class="w-5 h-5 text-orange-500"></i>
                    {% trans "Pending" %}
                    <span class="inline-flex items-center px-2.5 py-0.5 bg-orange-100 text-orange-700 rounded-full text-xs font-bold">
                        {{ pending_count }}
                    </span>
                </h2>
            </div>
            <div class="p-6">
                {% if pending_items %}
                <div class="space-y-4">
                    {% for item in pending_items %}
                    <div class="p-4 border-2 border-orange-100 rounded-xl hover:border-orange-300 hover:shadow-md transition-all duration-200">
                        <div class="flex items-start justify-between gap-3">
                            <div class="flex-1">
                                <div class="flex items-center gap-2 mb-2">
                                    <span class="inline-flex items-center px-2 py-1 bg-blue-50 text-blue-700 rounded-lg text-xs font-bold">
                                        {{ item.category.get_localized_name }}
                                    </span>
                                    {% if item.is_required %}
                                    <span class="inline-flex items-center px-2 py-1 bg-red-50 text-red-700 rounded-lg text-xs font-bold">
                                        {% trans "Required" %}
                                    </span>
                                    {% endif %}
                                </div>
                                <h3 class="font-bold text-navy mb-1">{{ item.get_localized_text }}</h3>
                                {% if item.get_localized_description %}
                                <p class="text-sm text-slate line-clamp-2">{{ item.get_localized_description }}</p>
                                {% endif %}
                            </div>
                            <a href="{% url 'accounts:acknowledgements:ack_sign' item.id %}" class="inline-flex items-center gap-2 px-4 py-2 bg-gradient-to-r from-orange-400 to-orange-500 text-white rounded-xl font-semibold hover:from-orange-500 hover:to-orange-600 transition shadow-lg shadow-orange-200 text-sm whitespace-nowrap">
                                {% trans "Sign Now" %}
                                <i data-lucide="arrow-right" class="w-4 h-4"></i>
                            </a>
                        </div>
                    </div>
                    {% endfor %}
                </div>
                {% else %}
                <div class="text-center py-12">
                    <div class="w-16 h-16 bg-gradient-to-br from-emerald-100 to-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i data-lucide="check-circle" class="w-8 h-8 text-emerald-500"></i>
                    </div>
                    <p class="text-slate font-medium">{% trans "All acknowledgements completed!" %}</p>
                </div>
                {% endif %}
            </div>
        </div>

        <!-- Completed Acknowledgements -->
        <div class="bg-white rounded-2xl shadow-sm border border-emerald-100 overflow-hidden">
            <div class="px-6 py-5 border-b border-emerald-100 bg-gradient-to-r from-emerald-50 to-transparent">
                <h2 class="text-lg font-bold text-navy flex items-center gap-2">
                    <i data-lucide="check-circle" class="w-5 h-5 text-emerald-500"></i>
                    {% trans "Completed" %}
                    <span class="inline-flex items-center px-2.5 py-0.5 bg-emerald-100 text-emerald-700 rounded-full text-xs font-bold">
                        {{ completed_count }}
                    </span>
                </h2>
            </div>
            <div class="p-6">
                {% if completed_acknowledgements %}
                <div class="space-y-4">
                    {% for ack in completed_acknowledgements %}
                    <div class="p-4 border-2 border-emerald-100 rounded-xl bg-emerald-50/30">
                        <div class="flex items-start justify-between gap-3">
                            <div class="flex-1">
                                <div class="flex items-center gap-2 mb-2">
                                    <span class="inline-flex items-center px-2 py-1 bg-blue-50 text-blue-700 rounded-lg text-xs font-bold">
                                        {{ ack.checklist_item.category.get_localized_name }}
                                    </span>
                                    <span class="inline-flex items-center px-2 py-1 bg-emerald-100 text-emerald-700 rounded-lg text-xs font-bold">
                                        <i data-lucide="check" class="w-3 h-3 mr-1"></i>
                                        {% trans "Signed" %}
                                    </span>
                                </div>
                                <h3 class="font-bold text-navy mb-1">{{ ack.checklist_item.get_localized_text }}</h3>
                                <p class="text-sm text-slate">
                                    <i data-lucide="calendar" class="w-3 h-3 inline mr-1"></i>
                                    {{ ack.acknowledged_at|date:"M d, Y" }}
                                </p>
                            </div>
                            {% if ack.pdf_file %}
                            <a href="{% url 'accounts:acknowledgements:ack_download_pdf' ack.id %}" class="inline-flex items-center gap-2 px-4 py-2 bg-white border-2 border-blue-200 text-blue-700 rounded-xl font-semibold hover:bg-blue-50 transition text-sm whitespace-nowrap">
                                <i data-lucide="download" class="w-4 h-4"></i>
                                {% trans "PDF" %}
                            </a>
                            {% endif %}
                        </div>
                    </div>
                    {% endfor %}
                </div>
                {% else %}
                <div class="text-center py-12">
                    <div class="w-16 h-16 bg-gradient-to-br from-blue-100 to-indigo-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i data-lucide="clipboard-list" class="w-8 h-8 text-blue-500"></i>
                    </div>
                    <p class="text-slate font-medium">{% trans "No completed acknowledgements yet" %}</p>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

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