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

{% block title %}{% trans "Acknowledgement Checklist Items" %} - 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="check-square" class="w-6 h-6 text-white"></i>
                </div>
                <div>
                    <h1 class="text-2xl font-bold">
                        {% trans "Checklist Items" %}
                    </h1>
                    <p class="text-white/80 text-sm">
                        {% trans "Manage acknowledgement checklist items" %}
                    </p>
                </div>
            </div>
            <div class="flex gap-3">
                <a href="{% url 'accounts:acknowledgements:ack_dashboard' %}" 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="arrow-left" class="w-4 h-4"></i>
                    {% trans "Back" %}
                </a>
                <a href="{% url 'accounts:acknowledgements:ack_checklist_create' %}" class="inline-flex items-center gap-2 px-5 py-2.5 bg-white text-purple-700 rounded-xl font-semibold hover:bg-purple-50 transition shadow-lg">
                    <i data-lucide="plus" class="w-4 h-4"></i>
                    {% trans "New Item" %}
                </a>
            </div>
        </div>
    </div>

    <!-- Filter Section -->
    <div class="section-card mb-6">
        <div class="p-4">
            <form method="get" class="flex flex-wrap gap-4 items-end">
                <div>
                    <label class="block text-xs font-semibold text-slate mb-1">{% trans "Category" %}</label>
                    <select name="category" class="px-4 py-2 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-blue focus:border-blue">
                        <option value="">{% trans "All Categories" %}</option>
                        {% for cat in categories %}
                        <option value="{{ cat.id }}" {% if request.GET.category == cat.id|stringformat:"s" %}selected{% endif %}>{{ cat.get_localized_name }}</option>
                        {% endfor %}
                    </select>
                </div>
                <div>
                    <label class="block text-xs font-semibold text-slate mb-1">{% trans "Status" %}</label>
                    <select name="is_active" class="px-4 py-2 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-blue focus:border-blue">
                        <option value="">{% trans "All" %}</option>
                        <option value="true" {% if request.GET.is_active == "true" %}selected{% endif %}>{% trans "Active" %}</option>
                        <option value="false" {% if request.GET.is_active == "false" %}selected{% endif %}>{% trans "Inactive" %}</option>
                    </select>
                </div>
                <button type="submit" class="px-4 py-2 bg-blue text-white rounded-xl text-sm font-semibold hover:bg-navy transition">
                    <i data-lucide="filter" class="w-4 h-4 inline mr-1"></i>
                    {% trans "Filter" %}
                </button>
                <a href="{% url 'accounts:acknowledgements:ack_checklist_list' %}" class="px-4 py-2 text-slate hover:text-navy text-sm">
                    {% trans "Clear" %}
                </a>
            </form>
        </div>
    </div>

    <!-- Checklist Items List -->
    <div class="section-card">
        <div class="section-header">
            <div class="section-icon bg-purple-100">
                <i data-lucide="list" class="w-5 h-5 text-purple-600"></i>
            </div>
            <h2 class="text-lg font-bold text-navy">{% trans "All Checklist Items" %}</h2>
            <span class="ml-2 px-2 py-0.5 bg-slate-100 text-slate text-sm rounded-full">{{ items.count }}</span>
        </div>
        <div class="p-6">
            {% if items %}
            <div class="overflow-x-auto">
                <table class="w-full">
                    <thead>
                        <tr class="border-b border-slate-200">
                            <th class="text-left py-3 px-4 text-xs font-semibold text-slate uppercase">{% trans "Item" %}</th>
                            <th class="text-left py-3 px-4 text-xs font-semibold text-slate uppercase">{% trans "Category" %}</th>
                            <th class="text-left py-3 px-4 text-xs font-semibold text-slate uppercase">{% trans "Code" %}</th>
                            <th class="text-left py-3 px-4 text-xs font-semibold text-slate uppercase">{% trans "Requires Signature" %}</th>
                            <th class="text-left py-3 px-4 text-xs font-semibold text-slate uppercase">{% trans "Status" %}</th>
                            <th class="text-right py-3 px-4 text-xs font-semibold text-slate uppercase">{% trans "Actions" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for item in items %}
                        <tr class="border-b border-slate-100 hover:bg-slate-50 transition">
                            <td class="py-4 px-4">
                                <div>
                                    <p class="font-semibold text-navy">{{ item.get_localized_text }}</p>
                                    {% if item.text_ar %}
                                    <p class="text-sm text-slate">{{ item.text_ar }}</p>
                                    {% endif %}
                                </div>
                            </td>
                            <td class="py-4 px-4">
                                <span class="inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-semibold" style="background-color: {{ item.category.color }}20; color: {{ item.category.color }}">
                                    {{ item.category.get_localized_name }}
                                </span>
                            </td>
                            <td class="py-4 px-4">
                                <span class="inline-flex items-center px-2 py-1 bg-slate-100 text-slate-700 rounded-lg text-xs font-mono">
                                    {{ item.code|default:"-" }}
                                </span>
                            </td>
                            <td class="py-4 px-4">
                                {% if item.requires_signature %}
                                <span class="inline-flex items-center gap-1 px-2 py-1 bg-blue-100 text-blue-700 rounded-lg text-xs font-semibold">
                                    <i data-lucide="pen-tool" class="w-3 h-3"></i>
                                    {% trans "Yes" %}
                                </span>
                                {% else %}
                                <span class="inline-flex items-center px-2 py-1 bg-slate-100 text-slate-500 rounded-lg text-xs">
                                    {% trans "No" %}
                                </span>
                                {% endif %}
                            </td>
                            <td class="py-4 px-4">
                                <span class="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-semibold {% if item.is_active %}bg-emerald-100 text-emerald-700{% else %}bg-red-100 text-red-700{% endif %}">
                                    <i data-lucide="{% if item.is_active %}check-circle{% else %}x-circle{% endif %}" class="w-3.5 h-3.5"></i>
                                    {% if item.is_active %}{% trans "Active" %}{% else %}{% trans "Inactive" %}{% endif %}
                                </span>
                            </td>
                            <td class="py-4 px-4 text-right">
                                <a href="{% url 'accounts:acknowledgements:ack_checklist_edit' item.id %}" class="inline-flex items-center gap-1 px-3 py-1.5 bg-purple-50 text-purple-700 rounded-lg text-sm font-semibold hover:bg-purple-100 transition">
                                    <i data-lucide="edit-2" class="w-4 h-4"></i>
                                    {% trans "Edit" %}
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <div class="text-center py-16">
                <div class="w-20 h-20 bg-gradient-to-br from-purple-100 to-indigo-100 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i data-lucide="check-square" class="w-10 h-10 text-purple-500"></i>
                </div>
                <h3 class="text-lg font-bold text-navy mb-2">{% trans "No Checklist Items" %}</h3>
                <p class="text-slate mb-6">{% trans "Create your first acknowledgement checklist item to get started." %}</p>
                <a href="{% url 'accounts:acknowledgements:ack_checklist_create' %}" class="inline-flex items-center gap-2 px-6 py-3 bg-gradient-to-r from-purple-500 to-indigo-500 text-white rounded-xl font-semibold hover:from-indigo-500 hover:to-purple-500 transition shadow-lg shadow-purple-200">
                    <i data-lucide="plus" class="w-5 h-5"></i>
                    {% trans "Create Item" %}
                </a>
            </div>
            {% endif %}
        </div>
    </div>
</div>

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