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

{% block title %}{% trans "Delete Source" %}{% endblock %}

{% block content %}
<div class="container-fluid">
    <!-- Page Header -->
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-2">
                    <li class="breadcrumb-item">
                        <a href="{% url 'px_sources:source_list' %}">{% trans "PX Sources" %}</a>
                    </li>
                    <li class="breadcrumb-item">
                        <a href="{% url 'px_sources:source_detail' source.pk %}">{{ source.name_en }}</a>
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">
                        {% trans "Delete" %}
                    </li>
                </ol>
            </nav>
            <h2 class="mb-1">
                <i class="bi bi-exclamation-triangle-fill text-danger me-2"></i>
                {% trans "Delete Source" %}
            </h2>
            <p class="text-muted mb-0">{{ source.name_en }}</p>
        </div>
        <div>
            <a href="{% url 'px_sources:source_detail' source.pk %}" class="btn btn-outline-secondary">
                <i class="bi bi-x-circle me-1"></i> {% trans "Cancel" %}
            </a>
        </div>
    </div>

    <!-- Delete Confirmation Card -->
    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0">
                <i class="bi bi-exclamation-circle me-2"></i>{% trans "Confirm Deletion" %}
            </h5>
        </div>
        <div class="card-body">
            <div class="alert alert-warning">
                <h4><i class="fas fa-exclamation-circle"></i> {% trans "Warning" %}</h4>
                <p>{% trans "Are you sure you want to delete this source? This action cannot be undone." %}</p>
            </div>

            <div class="table-responsive mb-4">
                <table class="table table-bordered">
                    <tr>
                        <th width="30%">{% trans "Name (English)" %}</th>
                        <td><strong>{{ source.name_en }}</strong></td>
                    </tr>
                    <tr>
                        <th>{% trans "Name (Arabic)" %}</th>
                        <td dir="rtl">{{ source.name_ar|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Description" %}</th>
                        <td>{{ source.description|default:"-"|truncatewords:20 }}</td>
                    </tr>
                    <tr>
                        <th>{% trans "Status" %}</th>
                        <td>
                            {% if source.is_active %}
                                <span class="badge bg-success">{% trans "Active" %}</span>
                            {% else %}
                                <span class="badge bg-secondary">{% trans "Inactive" %}</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th>{% trans "Usage Count" %}</th>
                        <td>
                            {% if usage_count > 0 %}
                                <span class="badge bg-danger">{{ usage_count }}</span>
                            {% else %}
                                <span class="badge bg-success">0</span>
                            {% endif %}
                        </td>
                    </tr>
                </table>
            </div>

            {% if usage_count > 0 %}
            <div class="alert alert-danger">
                <h5><i class="fas fa-exclamation-triangle"></i> {% trans "Cannot Delete" %}</h5>
                <p>{% trans "This source has been used in {{ usage_count }} record(s). You cannot delete sources that have usage records." %}</p>
                <p><strong>{% trans "Recommended action:" %}</strong> {% trans "Deactivate this source instead by editing it and unchecking the 'Active' checkbox." %}</p>
            </div>
            {% endif %}

            <form method="post">
                {% csrf_token %}
                {% if usage_count == 0 %}
                <button type="submit" class="btn btn-danger">
                    <i class="fas fa-trash"></i> {% trans "Yes, Delete" %}
                </button>
                {% else %}
                <button type="button" class="btn btn-danger" disabled>
                    <i class="fas fa-trash"></i> {% trans "Cannot Delete" %}
                </button>
                {% endif %}
                <a href="{% url 'px_sources:source_detail' source.pk %}" class="btn btn-secondary">
                    {% trans "Cancel" %}
                </a>
            </form>
        </div>
    </div>
</div>
{% endblock %}