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

{% block title %}{% trans "Standard Sources" %}{% endblock %}

{% block extra_css %}
<style>
    :root {
        --hh-navy: #005696;
        --hh-blue: #007bbd;
        --hh-light: #eef6fb;
        --hh-slate: #64748b;
    }

    .page-header-gradient {
        background: linear-gradient(135deg, var(--hh-navy) 0%, #0069a8 50%, var(--hh-blue) 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;
    }

    .table-container {
        padding: 0;
    }

    .standards-table {
        margin-bottom: 0;
    }

    .standards-table th {
        background: linear-gradient(to right, #f8fafc, #f1f5f9);
        font-weight: 600;
        color: #005696;
        border-bottom: 2px solid #e2e8f0;
        padding: 1rem 1.5rem;
        text-transform: uppercase;
        font-size: 0.75rem;
        letter-spacing: 0.05em;
    }

    .standards-table td {
        padding: 1rem 1.5rem;
        vertical-align: middle;
        border-bottom: 1px solid #f1f5f9;
    }

    .standards-table tbody tr:hover {
        background-color: #f8fafc;
    }

    .btn-transition {
        transition: all 0.2s ease-in-out;
    }
</style>
{% endblock %}

{% block content %}
<div class="px-6 py-4">
    <div class="page-header-gradient">
        <div class="flex justify-between items-center">
            <div>
                <h1 class="text-2xl font-bold mb-1">{% trans "Standard Sources" %}</h1>
                <p class="text-blue-100 text-sm">{% trans "Manage standard sources like CBAHI, JCI, ISO" %}</p>
            </div>
            <div class="flex gap-2">
                <a href="{% url 'standards:source_create' %}" class="btn-transition inline-flex items-center px-4 py-2.5 bg-green-500 text-white font-semibold rounded-xl hover:bg-green-600 transition">
                    <i data-lucide="plus" class="w-4 h-4 me-2"></i>{% trans "Add Source" %}
                </a>
            </div>
        </div>
    </div>

    <div class="section-card">
        <div class="section-header">
            <div class="section-icon bg-navy/10">
                <i data-lucide="book-open" class="w-5 h-5 text-navy"></i>
            </div>
            <h5 class="text-lg font-semibold text-navy">{% trans "Sources" %}</h5>
        </div>
        <div class="table-container">
            {% if sources %}
            <div class="overflow-x-auto">
                <table class="min-w-full standards-table">
                    <thead>
                        <tr>
                            <th class="px-4 py-3 text-left text-[10px] font-bold text-slate uppercase">
                                {% trans "Code" %}
                            </th>
                            <th class="px-4 py-3 text-left text-[10px] font-bold text-slate uppercase">
                                {% trans "Name" %}
                            </th>
                            <th class="px-4 py-3 text-left text-[10px] font-bold text-slate uppercase">
                                {% trans "Arabic Name" %}
                            </th>
                            <th class="px-4 py-3 text-left text-[10px] font-bold text-slate uppercase">
                                {% trans "Website" %}
                            </th>
                            <th class="px-4 py-3 text-left text-[10px] font-bold text-slate uppercase">
                                {% trans "Status" %}
                            </th>
                            <th class="px-4 py-3 text-right text-[10px] font-bold text-slate uppercase">
                                {% trans "Actions" %}
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for source in sources %}
                        <tr>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <span class="inline-flex items-center px-3 py-1 rounded-lg text-xs font-semibold bg-navy/10 text-navy">
                                    {{ source.code }}
                                </span>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                <div class="text-sm font-semibold text-navy">{{ source.name }}</div>
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-slate">
                                {{ source.name_ar|default:"-" }}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm">
                                {% if source.website %}
                                <a href="{{ source.website }}" target="_blank" rel="noopener" class="text-blue-600 hover:text-blue-800 transition">
                                    <i data-lucide="external-link" class="w-3 h-3 inline me-1"></i>{{ source.website }}
                                </a>
                                {% else %}
                                <span class="text-slate-400">-</span>
                                {% endif %}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap">
                                {% if source.is_active %}
                                <span class="inline-flex items-center px-2 py-1 rounded-full text-[10px] font-bold uppercase bg-green-100 text-green-800">
                                    <i data-lucide="check-circle" class="w-3 h-3 me-1"></i>{% trans "Active" %}
                                </span>
                                {% else %}
                                <span class="inline-flex items-center px-2 py-1 rounded-full text-[10px] font-bold uppercase bg-slate-100 text-navy">
                                    <i data-lucide="minus-circle" class="w-3 h-3 me-1"></i>{% trans "Inactive" %}
                                </span>
                                {% endif %}
                            </td>
                            <td class="px-6 py-4 whitespace-nowrap text-right">
                                <div class="flex gap-2 justify-end">
                                    <a href="{% url 'standards:source_update' pk=source.pk %}" 
                                       class="btn-transition inline-flex items-center px-3 py-1.5 bg-blue-500 text-white text-xs font-semibold rounded-lg hover:bg-blue-600 transition"
                                       title="{% trans 'Edit' %}">
                                        <i data-lucide="edit-2" class="w-3 h-3"></i>
                                    </a>
                                    <a href="{% url 'standards:source_delete' pk=source.pk %}" 
                                       class="btn-transition inline-flex items-center px-3 py-1.5 bg-red-500 text-white text-xs font-semibold rounded-lg hover:bg-red-600 transition"
                                       title="{% trans 'Delete' %}">
                                        <i data-lucide="trash-2" class="w-3 h-3"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <div class="text-center py-12 px-6 text-slate">
                <div class="w-16 h-16 mx-auto mb-4 bg-slate-100 rounded-full flex items-center justify-center">
                    <i data-lucide="book-open" class="w-8 h-8 text-slate-400"></i>
                </div>
                <h5 class="text-lg font-semibold text-slate-700 mb-2">{% trans "No sources found" %}</h5>
                <p class="mb-6 max-w-md mx-auto">{% trans "Add your first standard source to get started" %}</p>
                <a href="{% url 'standards:source_create' %}" class="btn-transition inline-flex items-center px-6 py-2.5 bg-green-500 text-white font-semibold rounded-xl hover:bg-green-600 transition mx-auto">
                    <i data-lucide="plus" class="w-4 h-4 me-2"></i>{% trans "Add Source" %}
                </a>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
