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

{% block content %}
<div class="container-fluid">
    <h1 class="page-title">Wallet Overview</h1>
    
    <div class="row mb-4">
        <div class="col-md-3">
            <div class="card stat-card">
                <div class="card-body">
                    <p class="text-muted mb-1 custom-text-muted">Available Balance</p>
                    <h3 class="mb-0 custom-text-white">${{ wallet.balance|floatformat:2 }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card">
                <div class="card-body">
                    <p class="text-muted mb-1 custom-text-muted">Total Deposits</p>
                    <h3 class="mb-0 custom-text-white">${{ wallet.total_deposits|floatformat:2 }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card earnings">
                <div class="card-body">
                    <p class="text-muted mb-1 custom-text-muted">Total Earnings</p>
                    <h3 class="mb-0 custom-text-success">${{ wallet.total_earnings|floatformat:2 }}</h3>
                </div>
            </div>
        </div>
        <div class="col-md-3">
            <div class="card stat-card referrals">
                <div class="card-body">
                    <p class="text-muted mb-1 custom-text-muted">Referral Earnings</p>
                    <h3 class="mb-0 custom-text-warning">${{ wallet.referral_earnings|floatformat:2 }}</h3>
                </div>
            </div>
        </div>
    </div>
    
    <div class="row">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0 custom-text-white">Recent Transactions</h5>
                    <a href="{% url 'transaction_history' %}" class="btn btn-sm btn-primary">View All</a>
                </div>
                <div class="card-body p-0">
                    {% if recent_transactions %}
                    <div class="table-responsive">
                        <table class="table mb-0">
                            <thead>
                                <tr>
                                    <th class="custom-text-muted">Type</th>
                                    <th class="custom-text-muted">Amount</th>
                                    <th class="custom-text-muted">Status</th>
                                    <th class="custom-text-muted">Date</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for transaction in recent_transactions %}
                                <tr>
                                    <td class="custom-text-muted">{{ transaction.get_transaction_type_display }}</td>
                                    <td class="{% if transaction.transaction_type == 'DEPOSIT' or transaction.transaction_type == 'REFERRAL_BONUS' %}custom-text-success{% else %}custom-text-danger{% endif %}">
                                        {% if transaction.transaction_type == 'DEPOSIT' or transaction.transaction_type == 'REFERRAL_BONUS' %}+{% else %}-{% endif %}
                                        ${{ transaction.amount|floatformat:2 }}
                                    </td>
                                    <td>
                                        <span class="badge badge-{{ transaction.status|lower }}">{{ transaction.get_status_display }}</span>
                                    </td>
                                    <td class="custom-text-muted">{{ transaction.created_at|date:"M d, Y" }}</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% else %}
                    <div class="text-center py-5">
                        <i class="bi bi-wallet2" style="font-size: 3rem; color: #64748b;"></i>
                        <p class="mt-3 custom-text-muted">No transactions yet.</p>
                    </div>
                    {% endif %}
                </div>
            </div>
        </div>
        
        <div class="col-md-4">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0 custom-text-white">Quick Actions</h5>
                </div>
                <div class="card-body">
                    <div class="d-grid gap-2">
                        <a href="{% url 'deposit_request' %}" class="btn btn-primary">
                            <i class="bi bi-plus-circle me-2"></i>Deposit
                        </a>
                        {% if user.is_verified %}
                        <a href="{% url 'withdraw_request' %}" class="btn btn-outline-primary">
                            <i class="bi bi-arrow-up-circle me-2"></i>Withdraw
                        </a>
                        {% else %}
                        <a href="{% url 'identity_verification' %}" class="btn btn-outline-primary">
                            <i class="bi bi-person-badge me-2"></i>Verify ID
                        </a>
                        {% endif %}
                        <a href="{% url 'transaction_history' %}" class="btn btn-outline-primary">
                            <i class="bi bi-clock-history me-2"></i>Transaction History
                        </a>
                    </div>
                    <div class="mt-3 p-3 rounded" style="background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border-color);">
                        <small class="custom-text-muted d-block mb-2">Withdrawal Access</small>
                        {% if user.verification_status == 'VERIFIED' %}
                        <span class="badge badge-approved">ID Verified</span>
                        {% elif user.verification_status == 'PENDING' %}
                        <span class="badge badge-pending">Verification Pending</span>
                        {% else %}
                        <span class="badge badge-rejected">Verification Required</span>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
