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

{% block content %}
<div class="container-fluid">
    <h1 class="page-title">Request Withdrawal</h1>

    <div class="row g-4">
        <div class="col-lg-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0 custom-text-white">Withdrawal Details</h5>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}

                        {% if form.non_field_errors %}
                        <div class="alert alert-danger">
                            {{ form.non_field_errors }}
                        </div>
                        {% endif %}

                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Amount</label>
                                {{ form.amount }}
                                {% if form.amount.errors %}
                                <div class="text-danger small mt-2">{{ form.amount.errors|join:", " }}</div>
                                {% endif %}
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label">Method</label>
                                {{ form.method }}
                                {% if form.method.errors %}
                                <div class="text-danger small mt-2">{{ form.method.errors|join:", " }}</div>
                                {% endif %}
                            </div>
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Wallet Address / Account Details</label>
                            {{ form.destination_details }}
                            {% if form.destination_details.errors %}
                            <div class="text-danger small mt-2">{{ form.destination_details.errors|join:", " }}</div>
                            {% endif %}
                        </div>

                        <div class="mb-3">
                            <label class="form-label">Notes</label>
                            {{ form.notes }}
                            {% if form.notes.errors %}
                            <div class="text-danger small mt-2">{{ form.notes.errors|join:", " }}</div>
                            {% endif %}
                        </div>

                        <div class="d-flex gap-2">
                            <button type="submit" class="btn btn-primary">Submit Withdrawal</button>
                            <a href="{% url 'wallet_overview' %}" class="btn btn-outline-primary">Back to Wallet</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="mb-0 custom-text-white">Wallet Summary</h5>
                </div>
                <div class="card-body">
                    <div class="mb-3">
                        <small class="custom-text-muted d-block">Available Balance</small>
                        <h3 class="mb-0 custom-text-white">${{ wallet.balance|floatformat:2 }}</h3>
                    </div>
                    <div>
                        <small class="custom-text-muted d-block mb-2">Verification</small>
                        <span class="badge badge-approved">Verified</span>
                    </div>
                </div>
            </div>

            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0 custom-text-white">Recent Requests</h5>
                </div>
                <div class="card-body">
                    {% if recent_requests %}
                    <div class="table-responsive">
                        <table class="table mb-0">
                            <thead>
                                <tr>
                                    <th class="custom-text-muted">Amount</th>
                                    <th class="custom-text-muted">Method</th>
                                    <th class="custom-text-muted">Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for withdrawal in recent_requests %}
                                <tr>
                                    <td class="custom-text-muted">${{ withdrawal.amount|floatformat:2 }}</td>
                                    <td class="custom-text-muted">{{ withdrawal.get_method_display }}</td>
                                    <td>
                                        <span class="badge badge-{{ withdrawal.status|lower }}">{{ withdrawal.get_status_display }}</span>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                    {% else %}
                    <p class="custom-text-muted mb-0">No withdrawal requests yet.</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
