{% extends 'index.html' %}
{% load static %}

{% block content %}
<div class="container d-flex justify-content-center">
    <div class="w-50 p-4 bg-light border rounded shadow-sm">
        <div class="text-center">
            <h2 class="text-danger">Delete Transaction</h2>

            {% if object.pk %}
                <p>Are you sure you want to delete <strong>"{{ object.transaction }}"</strong>?</p>

                <!-- Delete Form -->
                <form method="POST" action="{% url 'delete_transaction' object.pk %}" class="mt-3">
                    {% csrf_token %}

                    <!-- Bootstrap Modal Trigger -->
                    <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#confirmDeleteModal">
                        Delete This Transaction
                    </button>
                    <a href="{% url 'transactions' %}" class="btn btn-secondary">Cancel</a>

                    <!-- Modal -->
                    <div class="modal fade" id="confirmDeleteModal" tabindex="-1" aria-labelledby="confirmDeleteModalLabel" aria-hidden="true">
                        <div class="modal-dialog modal-dialog-centered">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title text-danger" id="confirmDeleteModalLabel">Confirm Delete</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    Are you sure you want to delete this transaction? This action cannot be undone.
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                                    <button type="submit" class="btn btn-danger">Yes, Delete</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            {% else %}
                <p class="text-danger">Error: Transaction not found.</p>
                <a href="{% url 'transactions' %}" class="btn btn-secondary">Back to Transactions</a>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
