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

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

{% block content %}
<div class="container-fluid px-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-0">{% trans "Standard Sources" %}</h1>
            <p class="text-muted mb-0">{% trans "Manage standard sources like CBAHI, JCI, ISO" %}</p>
        </div>
        <a href="{% url 'standards:source_create' %}" class="btn btn-primary">
            {% action_icon "create" %} {% trans "Add Source" %}
        </a>
    </div>

    <div class="card">
        <div class="card-body">
            {% if sources %}
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>{% trans "Code" %}</th>
                            <th>{% trans "Name" %}</th>
                            <th>{% trans "Arabic Name" %}</th>
                            <th>{% trans "Website" %}</th>
                            <th>{% trans "Status" %}</th>
                            <th>{% trans "Actions" %}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for source in sources %}
                        <tr>
                            <td><strong>{{ source.code }}</strong></td>
                            <td>{{ source.name }}</td>
                            <td>{{ source.name_ar|default:"-" }}</td>
                            <td>
                                {% if source.website %}
                                <a href="{{ source.website }}" target="_blank" rel="noopener">
                                    {{ source.website }}
                                </a>
                                {% else %}
                                -
                                {% endif %}
                            </td>
                            <td>
                                {% if source.is_active %}
                                <span class="badge bg-success">{% trans "Active" %}</span>
                                {% else %}
                                <span class="badge bg-secondary">{% trans "Inactive" %}</span>
                                {% endif %}
                            </td>
                            <td>
                                <div class="d-flex gap-1">
                                    <a href="{% url 'standards:source_update' pk=source.pk %}" class="btn btn-sm btn-outline-primary" title="{% trans 'Edit' %}">
                                        {% action_icon "edit" %}
                                    </a>
                                    <a href="{% url 'standards:source_delete' pk=source.pk %}" class="btn btn-sm btn-outline-danger" title="{% trans 'Delete' %}">
                                        {% action_icon "delete" %}
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <div class="text-center py-5">
                <span class="text-muted mb-3 d-block">{% action_icon "folder" size=64 %}</span>
                <h5>{% trans "No sources found" %}</h5>
                <p class="text-muted">{% trans "Add your first standard source to get started" %}</p>
                <a href="{% url 'standards:source_create' %}" class="btn btn-primary">
                    {% action_icon "create" %} {% trans "Add Source" %}
                </a>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
