{% extends 'base/base.html' %}
{% block title %}Referral History - CryptoSignals Pro{% endblock %}

{% block content %}
<div class="container-fluid">
    <h1 class="page-title">Referral History</h1>
    
    <div class="card">
        <div class="card-body">
            {% if page_obj %}
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th class="custom-text-muted">Bonus Type</th>
                            <th class="custom-text-muted">Related User</th>
                            <th class="custom-text-muted">Deposit Amount</th>
                            <th class="custom-text-muted">Rate / Level</th>
                            <th class="custom-text-muted">Amount</th>
                            <th class="custom-text-muted">Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for earning in page_obj %}
                        <tr>
                            <td class="custom-text-muted">{{ earning.get_earning_type_display }}</td>
                            <td class="custom-text-muted">
                                {% if earning.referred_user %}
                                {{ earning.referred_user.username }}
                                {% else %}
                                Team milestone
                                {% endif %}
                            </td>
                            <td class="custom-text-muted">
                                {% if earning.deposit_amount %}
                                ${{ earning.deposit_amount|floatformat:2 }}
                                {% else %}
                                -
                                {% endif %}
                            </td>
                            <td class="custom-text-muted">
                                {% if earning.percentage_applied %}
                                {{ earning.percentage_applied }}%
                                {% elif earning.level_achieved %}
                                Level {{ earning.level_achieved }}
                                {% else %}
                                -
                                {% endif %}
                            </td>
                            <td class="custom-text-success">${{ earning.amount|floatformat:2 }}</td>
                            <td class="custom-text-muted">{{ earning.created_at|date:"M d, Y" }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            
            {% if page_obj.has_other_pages %}
            <nav>
                <ul class="pagination justify-content-center">
                    {% if page_obj.has_previous %}
                    <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">Previous</a></li>
                    {% endif %}
                    <li class="page-item active"><span class="page-link">Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}</span></li>
                    {% if page_obj.has_next %}
                    <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">Next</a></li>
                    {% endif %}
                </ul>
            </nav>
            {% endif %}
            {% else %}
            <p class="text-center custom-text-muted py-4">No referral history.</p>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
