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

{% block title %}{% trans "Appreciation Badges" %} - 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;
    }

    .badge-card {
        background: white;
        border-radius: 1rem;
        border: 2px solid #e2e8f0;
        overflow: hidden;
        transition: all 0.3s ease;
    }
    .badge-card:hover {
        border-color: #f59e0b;
        box-shadow: 0 10px 25px -5px rgba(245, 158, 11, 0.2);
    }
</style>
{% endblock %}

{% block content %}
<!-- Page Header Gradient -->
<div class="page-header-gradient">
    <div class="flex justify-between items-start">
        <div>
            <h1 class="text-2xl font-bold flex items-center gap-3">
                <i data-lucide="award" class="w-7 h-7"></i>
                {% trans "Appreciation Badges" %}
            </h1>
            <p class="text-sm opacity-90 mt-1">{% trans "Create and manage badges to recognize achievements" %}</p>
        </div>
        <a href="{% url 'appreciation:badge_create' %}" class="bg-white text-navy px-5 py-2.5 rounded-xl text-sm font-bold shadow-lg hover:bg-gray-100 flex items-center gap-2 transition">
            <i data-lucide="plus" class="w-4 h-4"></i> {% trans "Add Badge" %}
        </a>
    </div>
</div>

<!-- Breadcrumb -->
<nav class="mb-6 text-sm">
    <ol class="flex items-center gap-2 text-slate">
        <li><a href="{% url 'appreciation:appreciation_list' %}" class="hover:text-navy transition">{% trans "Appreciation" %}</a></li>
        <li><i data-lucide="chevron-right" class="w-4 h-4"></i></li>
        <li class="text-navy font-medium">{% trans "Badges" %}</li>
    </nav>
</nav>

<!-- Badges List -->
<div class="section-card">
    <div class="section-header">
        <div class="section-icon bg-amber-100">
            <i data-lucide="award" class="w-5 h-5 text-amber-600"></i>
        </div>
        <h3 class="font-bold text-navy">{% trans "All Badges" %}</h3>
    </div>
    <div class="p-6">
        {% if badges %}
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                {% for badge in badges %}
                    <div class="badge-card h-full flex flex-col">
                        <div class="p-6 flex-1">
                            <div class="text-center mb-4">
                                <div class="w-20 h-20 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4">
                                    <i data-lucide="{{ badge.icon|default:'award' }}" class="w-10 h-10 text-amber-600"></i>
                                </div>
                                <h5 class="font-bold text-navy text-lg">{{ badge.get_localized_name }}</h5>
                                <p class="text-sm text-slate mt-2">{{ badge.description_en|truncatewords:10 }}</p>
                            </div>
                            <hr class="border-slate-200 my-4">
                            <ul class="space-y-2 text-sm">
                                <li class="flex justify-between">
                                    <span class="text-slate">{% trans "Type:" %}</span>
                                    <span class="font-medium text-navy">{{ badge.get_criteria_type_display }}</span>
                                </li>
                                <li class="flex justify-between">
                                    <span class="text-slate">{% trans "Value:" %}</span>
                                    <span class="font-medium text-navy">{{ badge.criteria_value }}</span>
                                </li>
                                <li class="flex justify-between">
                                    <span class="text-slate">{% trans "Earned:" %}</span>
                                    <span class="font-medium text-navy">{{ badge.earned_count }} {% trans "times" %}</span>
                                </li>
                                <li class="flex justify-between items-center">
                                    <span class="text-slate">{% trans "Status:" %}</span>
                                    {% if badge.is_active %}
                                        <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold bg-green-100 text-green-700">
                                            {% trans "Active" %}
                                        </span>
                                    {% else %}
                                        <span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-bold bg-gray-100 text-gray-700">
                                            {% trans "Inactive" %}
                                        </span>
                                    {% endif %}
                                </li>
                            </ul>
                        </div>
                        <div class="p-4 border-t border-slate-200 bg-slate-50 flex gap-2">
                            <a href="{% url 'appreciation:badge_edit' badge.id %}" class="flex-1 bg-white border border-navy text-navy px-4 py-2 rounded-lg text-sm font-medium hover:bg-navy hover:text-white transition flex items-center justify-center gap-2">
                                <i data-lucide="pencil" class="w-4 h-4"></i> {% trans "Edit" %}
                            </a>
                            <a href="{% url 'appreciation:badge_delete' badge.id %}" class="flex-1 bg-white border border-red-500 text-red-500 px-4 py-2 rounded-lg text-sm font-medium hover:bg-red-500 hover:text-white transition flex items-center justify-center gap-2">
                                <i data-lucide="trash-2" class="w-4 h-4"></i> {% trans "Delete" %}
                            </a>
                        </div>
                    </div>
                {% endfor %}
            </div>

            <!-- Pagination -->
            {% if page_obj.has_other_pages %}
                <div class="mt-8 pt-6 border-t border-slate-100 flex justify-center">
                    <div class="flex items-center gap-2">
                        {% if page_obj.has_previous %}
                            <a href="?page={{ page_obj.previous_page_number }}" 
                               class="px-3 py-2 rounded-lg border border-slate-200 text-slate hover:bg-light transition">
                                {% trans "Previous" %}
                            </a>
                        {% else %}
                            <span class="px-3 py-2 rounded-lg border border-slate-200 text-gray-300 cursor-not-allowed">
                                {% trans "Previous" %}
                            </span>
                        {% endif %}

                        {% for num in page_obj.paginator.page_range %}
                            {% if page_obj.number == num %}
                                <span class="px-4 py-2 rounded-lg bg-navy text-white font-bold">{{ num }}</span>
                            {% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
                                <a href="?page={{ num }}" 
                                   class="px-4 py-2 rounded-lg border border-slate-200 text-slate hover:bg-light transition">
                                    {{ num }}
                                </a>
                            {% endif %}
                        {% endfor %}

                        {% if page_obj.has_next %}
                            <a href="?page={{ page_obj.next_page_number }}" 
                               class="px-3 py-2 rounded-lg border border-slate-200 text-slate hover:bg-light transition">
                                {% trans "Next" %}
                            </a>
                        {% else %}
                            <span class="px-3 py-2 rounded-lg border border-slate-200 text-gray-300 cursor-not-allowed">
                                {% trans "Next" %}
                            </span>
                        {% endif %}
                    </div>
                </div>
            {% endif %}
        {% else %}
            <div class="text-center py-12">
                <div class="w-16 h-16 bg-amber-50 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i data-lucide="award" class="w-8 h-8 text-amber-400"></i>
                </div>
                <h4 class="text-lg font-bold text-navy mb-2">{% trans "No badges found" %}</h4>
                <p class="text-slate mb-4">{% trans "Create badges to motivate and recognize achievements" %}</p>
                <a href="{% url 'appreciation:badge_create' %}" class="bg-navy text-white px-5 py-2.5 rounded-xl text-sm font-bold hover:bg-blue transition inline-flex items-center gap-2">
                    <i data-lucide="plus" class="w-4 h-4"></i> {% trans "Add Badge" %}
                </a>
            </div>
        {% endif %}
    </div>
</div>
{% endblock %}
