<!-- templates/subscriptions/offer_detail.html -->
{% extends "subscriptions/base.html" %}

{% block title %}Offer Detail: {{ offer_id }} - {{ month_name }}{% endblock %}

{% block content %}
<div class="max-w-6xl mx-auto">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-3xl font-bold text-gray-800">{{ offer_id }} - {{ month_name }}</h1>

        <a href="{% url 'monthly_summary' %}"
           class="bg-gray-500 hover:bg-gray-600 text-white font-medium py-2 px-4 rounded inline-flex items-center">
            <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
                <path fill-rule="evenodd" d="M9.707 16.707a1 1 0 01-1.414 0l-6-6a1 1 0 010-1.414l6-6a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l4.293 4.293a1 1 0 010 1.414z" clip-rule="evenodd" />
            </svg>
            Back to Summary
        </a>
    </div>

    {% if notifications %}
        <div class="bg-white shadow-md rounded-lg overflow-hidden mb-8">
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Signed Date
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Notification Type
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Original Transaction ID
                            </th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                Offer Identifier
                            </th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        {% for notification in notifications %}
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    {{ notification.signedDate }}
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    {% if notification.notificationType == 'SUBSCRIBED' %}
                                        <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                            {{ notification.notificationType }}
                                        </span>
                                    {% elif notification.notificationType == 'REFUND' %}
                                        <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">
                                            {{ notification.notificationType }}
                                        </span>
                                    {% else %}
                                        {{ notification.notificationType }}
                                    {% endif %}
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    {{ notification.originalTransactionId }}
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    {{ notification.offerIdentifier }}
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>

        <div class="bg-white shadow-md rounded-lg overflow-hidden">
            <div class="px-6 py-4 bg-gray-50 border-b border-gray-200">
                <h3 class="text-lg font-medium text-gray-800">Summary</h3>
            </div>
            <div class="p-6">
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
                    <div class="bg-green-50 rounded-lg p-4 border border-green-200">
                        <h4 class="text-green-800 text-lg font-medium mb-2">Subscribed</h4>
                        <p class="text-3xl font-bold text-green-600">{{ subscribed_count }}</p>
                    </div>

                    <div class="bg-red-50 rounded-lg p-4 border border-red-200">
                        <h4 class="text-red-800 text-lg font-medium mb-2">Refunds</h4>
                        <p class="text-3xl font-bold text-red-600">{{ refund_count }}</p>
                    </div>

                    <div class="bg-blue-50 rounded-lg p-4 border border-blue-200">
                        <h4 class="text-blue-800 text-lg font-medium mb-2">Net Subscriptions</h4>
                        <p class="text-3xl font-bold text-blue-600">{{ net_count }}</p>
                    </div>

                    <div class="bg-purple-50 rounded-lg p-4 border border-purple-200">
                        <h4 class="text-purple-800 text-lg font-medium mb-2">Revenue ($15/sub)</h4>
                        <p class="text-3xl font-bold text-purple-600">${{ revenue }}</p>
                    </div>
                </div>
            </div>
        </div>
    {% else %}
        <div class="bg-blue-50 border-l-4 border-blue-500 text-blue-700 p-4" role="alert">
            <p>No subscription or refund notifications found for this offer in {{ month_name }}.</p>
        </div>
    {% endif %}
</div>
{% endblock %}
