{% extends 'base.html' %}
{% load humanize %}

{% block title %}Registration Fee Payment Details{% endblock %}

{% block content %}
<div class="container mx-auto px-4 sm:px-6 lg:px-8 py-6">
    <!-- Page Header -->
    <div class="mb-8">
        <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4">
            <div>
                <h1 class="text-3xl font-bold text-gray-900 dark:text-white">Payment Receipt</h1>
                <p class="text-gray-600 dark:text-gray-400 mt-1">Registration fee payment details</p>
            </div>
            <div class="flex gap-2">
                <a href="{% url 'reports:record_registration_fee_payment' %}"
                    class="inline-flex items-center px-4 py-2 text-sm font-medium text-gray-600 bg-gray-100 rounded-lg hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600 transition-colors">
                    <span>←</span> Back
                </a>
                <button onclick="window.print()"
                    class="inline-flex items-center px-4 py-2 text-sm font-medium text-white bg-gradient-to-r from-blue-600 to-purple-600 rounded-lg hover:from-blue-700 hover:to-purple-700 transition-all transform hover:-translate-y-0.5">
                    <span>🖨️</span> Print Receipt
                </button>
            </div>
        </div>
    </div>

    <!-- Payment Receipt -->
    <div class="bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8" id="receipt">
        <!-- Receipt Header -->
        <div class="text-center mb-8 border-b border-gray-200 dark:border-gray-700 pb-6">
            <h2 class="text-2xl font-bold text-gray-900 dark:text-white mb-2">HAVEN GRAZURI INVESTMENT LIMITED</h2>
            <p class="text-gray-600 dark:text-gray-400">Registration Fee Payment Receipt</p>
            <div class="mt-4">
                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200">
                    <span>✓</span> Payment Confirmed
                </span>
            </div>
        </div>

        <!-- Receipt Details -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-8">
            <!-- Payment Information -->
            <div>
                <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Payment Information</h3>
                <div class="space-y-3">
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Receipt Number:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.receipt_number }}</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Payment Date:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.payment_date|date:"M d, Y H:i" }}</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Payment Method:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.get_payment_method_display }}</span>
                    </div>
                    {% if payment.transaction_reference %}
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Transaction Ref:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.transaction_reference }}</span>
                    </div>
                    {% endif %}
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Processed By:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.processed_by.get_full_name }}</span>
                    </div>
                </div>
            </div>

            <!-- Customer Information -->
            <div>
                <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Customer Information</h3>
                <div class="space-y-3">
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Name:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.customer.get_full_name }}</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Phone:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.customer.phone_number|default:"N/A" }}</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Email:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.customer.email|default:"N/A" }}</span>
                    </div>
                    <div class="flex justify-between">
                        <span class="text-gray-600 dark:text-gray-400">Customer ID:</span>
                        <span class="font-semibold text-gray-900 dark:text-white">{{ payment.customer.customer_number|default:payment.customer.id }}</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Fee Details -->
        <div class="border-t border-gray-200 dark:border-gray-700 pt-6 mb-8">
            <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-4">Fee Details</h3>
            <div class="bg-gray-50 dark:bg-gray-700 rounded-lg p-4">
                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                    <div>
                        <span class="text-sm text-gray-600 dark:text-gray-400">Fee Name</span>
                        <p class="font-semibold text-gray-900 dark:text-white">{{ payment.registration_fee.fee_name }}</p>
                    </div>
                    <div>
                        <span class="text-sm text-gray-600 dark:text-gray-400">Product Type</span>
                        <p class="font-semibold text-gray-900 dark:text-white">{{ payment.registration_fee.get_product_type_display }}</p>
                    </div>
                    <div>
                        <span class="text-sm text-gray-600 dark:text-gray-400">Standard Amount</span>
                        <p class="font-semibold text-gray-900 dark:text-white">KES {{ payment.registration_fee.amount|floatformat:2|intcomma }}</p>
                    </div>
                </div>
                {% if payment.registration_fee.description %}
                <div class="mt-3">
                    <span class="text-sm text-gray-600 dark:text-gray-400">Description</span>
                    <p class="text-gray-900 dark:text-white">{{ payment.registration_fee.description }}</p>
                </div>
                {% endif %}
            </div>
        </div>

        <!-- Payment Summary -->
        <div class="border-t border-gray-200 dark:border-gray-700 pt-6">
            <div class="bg-gradient-to-r from-blue-50 to-purple-50 dark:from-blue-900 dark:to-purple-900 rounded-lg p-6">
                <div class="flex justify-between items-center">
                    <span class="text-xl font-semibold text-gray-900 dark:text-white">Amount Paid:</span>
                    <span class="text-3xl font-bold text-blue-600 dark:text-blue-400">KES {{ payment.amount_paid|floatformat:2|intcomma }}</span>
                </div>
                {% if payment.amount_paid != payment.registration_fee.amount %}
                <div class="mt-2 text-sm text-gray-600 dark:text-gray-400">
                    {% if payment.amount_paid > payment.registration_fee.amount %}
                        <span>ℹ️</span> Overpayment of KES {{ payment.amount_paid|sub:payment.registration_fee.amount|floatformat:2|intcomma }}
                    {% else %}
                        <span>⚠️</span> Partial payment - Balance: KES {{ payment.registration_fee.amount|sub:payment.amount_paid|floatformat:2|intcomma }}
                    {% endif %}
                </div>
                {% endif %}
            </div>
        </div>

        <!-- Payment Notes -->
        {% if payment.payment_notes %}
        <div class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-6">
            <h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-3">Payment Notes</h3>
            <div class="bg-yellow-50 dark:bg-yellow-900 border border-yellow-200 dark:border-yellow-700 rounded-lg p-4">
                <p class="text-gray-900 dark:text-white">{{ payment.payment_notes }}</p>
            </div>
        </div>
        {% endif %}

        <!-- Footer -->
        <div class="border-t border-gray-200 dark:border-gray-700 pt-6 mt-8 text-center">
            <p class="text-sm text-gray-600 dark:text-gray-400">
                This is a computer-generated receipt. No signature required.
            </p>
            <p class="text-xs text-gray-500 dark:text-gray-500 mt-2">
                Generated on {{ payment.created_at|date:"M d, Y H:i" }}
            </p>
        </div>
    </div>
</div>

<style>
@media print {
    .lg\:ml-72 {
        margin-left: 0 !important;
    }
    
    .no-print {
        display: none !important;
    }
    
    #receipt {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
    }
}
</style>
{% endblock %}