{% extends 'service_partner_app/base_service_partner.html' %}
{% load static %}

{% block title %}Service Partner Wallet Top-up{% endblock %}

{% block content %}

<style>
    /* =========================================================
       SERVICE PARTNER WALLET TOP-UP
    ========================================================= */

    .service-wallet-page {
        min-height: 100vh;
        padding: 4rem 0 5rem;
        background:
            radial-gradient(circle at top left, rgba(37, 99, 235, 0.10), transparent 30%),
            radial-gradient(circle at top right, rgba(16, 185, 129, 0.10), transparent 32%),
            linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
    }

    .service-wallet-hero {
        position: relative;
        overflow: hidden;
        border-radius: 36px;
        padding: 2.8rem 2.5rem;
        margin-bottom: 2rem;
        background:
            radial-gradient(circle at top right, rgba(96, 165, 250, 0.22), transparent 34%),
            linear-gradient(135deg, #0f172a 0%, #1d4ed8 48%, #0f766e 100%);
        color: #ffffff;
        box-shadow: 0 28px 68px rgba(30, 64, 175, 0.18);
    }

    .service-wallet-hero::before {
        content: "";
        position: absolute;
        top: -95px;
        right: -70px;
        width: 260px;
        height: 260px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.09);
        pointer-events: none;
    }

    .service-wallet-hero::after {
        content: "";
        position: absolute;
        bottom: -120px;
        left: -80px;
        width: 310px;
        height: 310px;
        border-radius: 50%;
        background: rgba(167, 243, 208, 0.11);
        pointer-events: none;
    }

    .service-wallet-hero-inner {
        position: relative;
        z-index: 2;
    }

    .service-wallet-mini-title {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.48rem 0.95rem;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.14);
        border: 1px solid rgba(255, 255, 255, 0.22);
        color: #dbeafe;
        font-size: 0.84rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.045em;
        margin-bottom: 1rem;
    }

    .service-wallet-hero h1 {
        font-size: clamp(2.2rem, 4vw, 3.6rem);
        font-weight: 950;
        letter-spacing: -0.045em;
        line-height: 1.07;
        margin-bottom: 0.95rem;
    }

    .service-wallet-hero p {
        max-width: 920px;
        color: rgba(255, 255, 255, 0.88);
        font-size: 1.04rem;
        line-height: 1.78;
        margin-bottom: 0;
    }

    .service-wallet-panel {
        margin-top: 1.35rem;
        border-radius: 28px;
        padding: 1.35rem;
        background: rgba(255, 255, 255, 0.12);
        border: 1px solid rgba(255, 255, 255, 0.18);
        backdrop-filter: blur(6px);
    }

    .service-wallet-panel-item {
        height: 100%;
        border-radius: 22px;
        padding: 1rem 1.05rem;
        background: rgba(255, 255, 255, 0.97);
        color: #111827 !important;
        box-shadow: 0 14px 28px rgba(15, 23, 42, 0.08);
    }

    .service-wallet-label {
        display: block;
        color: #6b7280 !important;
        font-size: 0.78rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.4rem;
    }

    .service-wallet-value {
        color: #111827 !important;
        font-weight: 950;
        font-size: 1.08rem;
        line-height: 1.4;
        margin-bottom: 0;
    }

    .service-wallet-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.85rem;
        margin-top: 1.5rem;
    }

    .service-wallet-actions .btn {
        border-radius: 999px;
        font-weight: 850;
        padding: 0.82rem 1.35rem;
        min-height: 48px;
    }

    .service-btn-primary-soft {
        background: #dbeafe;
        color: #1e3a8a;
        border: none;
    }

    .service-btn-primary-soft:hover {
        background: #bfdbfe;
        color: #1e3a8a;
        transform: translateY(-1px);
    }

    .service-btn-light-outline {
        background: rgba(255, 255, 255, 0.10);
        color: #ffffff;
        border: 1px solid rgba(255, 255, 255, 0.42);
    }

    .service-btn-light-outline:hover {
        background: #ffffff;
        color: #1e3a8a;
    }

    .service-wallet-card {
        border-radius: 34px;
        background: rgba(255, 255, 255, 0.99);
        border: 1px solid rgba(219, 234, 254, 0.95);
        box-shadow: 0 24px 56px rgba(30, 64, 175, 0.09);
        overflow: hidden;
        margin-bottom: 1.5rem;
    }

    .service-wallet-card-header {
        padding: 1.65rem 1.8rem 1.15rem;
        border-bottom: 1px solid #dbeafe;
        background:
            radial-gradient(circle at top right, rgba(59, 130, 246, 0.08), transparent 28%),
            linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    }

    .service-wallet-card-header h2,
    .service-wallet-card-header h3 {
        color: #111827;
        font-weight: 950;
        margin-bottom: 0.35rem;
    }

    .service-wallet-card-header p {
        color: #6b7280;
        line-height: 1.7;
        margin-bottom: 0;
    }

    .service-wallet-card-body {
        padding: 1.8rem;
    }

    .service-form-group {
        margin-bottom: 1.35rem;
    }

    .service-form-group label {
        display: block;
        color: #111827;
        font-weight: 850;
        margin-bottom: 0.5rem;
    }

    .service-form-group input,
    .service-form-group select,
    .service-form-group textarea {
        border-radius: 18px;
        border: 1px solid #bfdbfe;
        background: #f8fbff;
        min-height: 52px;
        color: #111827;
        transition: all 0.2s ease;
    }

    .service-form-group input:focus,
    .service-form-group select:focus,
    .service-form-group textarea:focus {
        border-color: #2563eb;
        background: #ffffff;
        box-shadow: 0 0 0 0.22rem rgba(37, 99, 235, 0.13);
    }

    .service-field-error {
        color: #dc2626;
        font-size: 0.86rem;
        font-weight: 750;
        margin-top: 0.4rem;
    }

    .quick-amount-grid {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.75rem;
        margin-top: 0.85rem;
    }

    .quick-amount-btn {
        border-radius: 18px;
        border: 1px solid #bfdbfe;
        background: #ffffff;
        color: #1e3a8a;
        padding: 0.8rem 0.75rem;
        font-weight: 900;
        transition: 0.2s ease;
    }

    .quick-amount-btn:hover {
        border-color: #2563eb;
        background: #eff6ff;
        color: #1d4ed8;
        transform: translateY(-1px);
    }

    .payment-method-list {
        display: grid;
        gap: 0.9rem;
    }

    .payment-method-card {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        border: 1.5px solid #bfdbfe;
        border-radius: 1.15rem;
        padding: 0.95rem 1rem;
        background: #ffffff;
        cursor: pointer;
        transition: all 0.2s ease-in-out;
        min-height: 78px;
    }

    .payment-method-card:hover {
        border-color: #2563eb;
        box-shadow: 0 0.45rem 1rem rgba(30, 64, 175, 0.08);
    }

    .payment-method-left {
        display: flex;
        align-items: center;
        gap: 0.9rem;
        min-width: 0;
    }

    .payment-method-icon {
        width: 46px;
        height: 46px;
        border-radius: 0.9rem;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        flex-shrink: 0;
    }

    .stripe-card .payment-method-icon {
        background: #eef4ff;
        color: #635bff;
    }

    .paypal-card .payment-method-icon {
        background: #eef7ff;
        color: #0070ba;
    }

    .payment-method-title {
        font-weight: 900;
        color: #111827;
        line-height: 1.2;
    }

    .payment-method-subtitle {
        font-size: 0.9rem;
        color: #6b7280;
        line-height: 1.35;
        margin-top: 0.15rem;
    }

    .payment-method-right {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        flex-shrink: 0;
    }

    .payment-method-status {
        font-size: 0.78rem;
        font-weight: 850;
        color: #1d4ed8;
        background: #eff6ff;
        border: 1px solid #bfdbfe;
        border-radius: 999px;
        padding: 0.3rem 0.65rem;
    }

    .payment-method-check {
        color: #1d4ed8;
        font-size: 1.15rem;
        opacity: 0;
        transition: opacity 0.2s ease-in-out;
        line-height: 1;
    }

    .btn-check:checked + .payment-method-card {
        border-color: #2563eb;
        background: #eff6ff;
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
    }

    .btn-check:checked + .payment-method-card .payment-method-check {
        opacity: 1;
    }

    .service-wallet-submit {
        border-radius: 999px;
        min-height: 54px;
        font-weight: 900;
        background: linear-gradient(135deg, #0f172a, #1d4ed8, #0f766e);
        color: #ffffff;
        border: none;
        box-shadow: 0 14px 28px rgba(37, 99, 235, 0.20);
    }

    .service-wallet-submit:hover {
        color: #1e3a8a;
        background: linear-gradient(135deg, #dbeafe, #ecfdf5);
        transform: translateY(-2px);
    }

    .service-note-box {
        border-radius: 24px;
        padding: 1rem 1.1rem;
        background: #fff7ed;
        border: 1px solid #fed7aa;
        color: #92400e;
        line-height: 1.7;
    }

    .service-note-box strong {
        color: #111827;
    }

    .service-side-stat {
        border-radius: 24px;
        padding: 1.15rem;
        background: #f8fbff;
        border: 1px solid #bfdbfe;
        margin-bottom: 0.9rem;
    }

    .service-side-stat span {
        display: block;
        color: #6b7280;
        font-size: 0.78rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.35rem;
    }

    .service-side-stat strong {
        color: #111827;
        font-weight: 950;
        font-size: 1.18rem;
    }

    .service-wallet-balance-box {
        border-radius: 28px;
        padding: 1.35rem;
        color: #ffffff;
        background:
            radial-gradient(circle at top right, rgba(96, 165, 250, 0.22), transparent 34%),
            linear-gradient(135deg, #0f172a 0%, #1d4ed8 55%, #0f766e 100%);
        margin-bottom: 1rem;
    }

    .service-wallet-balance-box span {
        display: block;
        color: rgba(255, 255, 255, 0.72);
        font-size: 0.78rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.35rem;
    }

    .service-wallet-balance-box strong {
        display: block;
        color: #ffffff;
        font-size: 2.35rem;
        font-weight: 950;
        letter-spacing: -0.04em;
        line-height: 1;
    }

    @media (max-width: 991.98px) {
        .service-wallet-page {
            padding-top: 2.8rem;
        }

        .service-wallet-hero {
            padding: 2rem 1.45rem;
            border-radius: 30px;
        }
    }

    @media (max-width: 767.98px) {
        .service-wallet-card-body,
        .service-wallet-card-header {
            padding-left: 1.15rem;
            padding-right: 1.15rem;
        }

        .service-wallet-actions {
            flex-direction: column;
            align-items: stretch;
        }

        .service-wallet-actions .btn {
            width: 100%;
        }

        .quick-amount-grid {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }

        .payment-method-card {
            padding: 0.9rem;
        }
    }
</style>


<section class="service-wallet-page">
    <div class="container">

        <div class="service-wallet-hero">
            <div class="service-wallet-hero-inner">

                <span class="service-wallet-mini-title">
                    <i class="bi bi-wallet2"></i>
                    Service Partner Wallet
                </span>

                <h1>Top Up Your Wallet</h1>

                <p>
                    Add funds to your Service Partner wallet so you can pay featured profile fees,
                    premium visibility upgrades, service-related platform charges, and other eligible partner payments.
                </p>

                <div class="service-wallet-panel">
                    <div class="row g-3">

                        <div class="col-md-4">
                            <div class="service-wallet-panel-item">
                                <span class="service-wallet-label">Account</span>
                                <p class="service-wallet-value">
                                    {{ partner.user.get_full_name|default:partner.user.username }}
                                </p>
                            </div>
                        </div>

                        <div class="col-md-4">
                            <div class="service-wallet-panel-item">
                                <span class="service-wallet-label">Wallet Type</span>
                                <p class="service-wallet-value">
                                    {{ account_label|default:"Service Partner Wallet" }}
                                </p>
                            </div>
                        </div>

                        <div class="col-md-4">
                            <div class="service-wallet-panel-item">
                                <span class="service-wallet-label">Current Balance</span>
                                <p class="service-wallet-value">
                                    USD {{ wallet.balance_usd|floatformat:2 }}
                                </p>
                            </div>
                        </div>

                    </div>
                </div>

                <div class="service-wallet-actions">
                    <a href="{% url 'service_partner_app:service_partner_payment_center' %}"
                       class="btn service-btn-light-outline">
                        <i class="bi bi-arrow-left-circle me-2"></i>
                        Back to Payment Center
                    </a>

                    <a href="{% url 'service_partner_app:service_partner_dashboard' %}"
                       class="btn service-btn-light-outline">
                        <i class="bi bi-speedometer2 me-2"></i>
                        My Dashboard
                    </a>

                    <a href="{% url 'service_partner_app:home_service_partner' %}"
                       class="btn service-btn-primary-soft">
                        <i class="bi bi-tools me-2"></i>
                        Services Home
                    </a>
                </div>

            </div>
        </div>


        <div class="row g-4 align-items-start">

            <div class="col-lg-8">
                <div class="service-wallet-card">

                    <div class="service-wallet-card-header">
                        <h2>Top-up Details</h2>
                        <p>
                            Enter the amount you want to add to your wallet and choose your preferred payment method.
                        </p>
                    </div>

                    <div class="service-wallet-card-body">

                        <form method="post">
                            {% csrf_token %}

                            {% if form.non_field_errors %}
                                <div class="alert alert-danger rounded-4">
                                    {% for error in form.non_field_errors %}
                                        <div>{{ error }}</div>
                                    {% endfor %}
                                </div>
                            {% endif %}

                            <div class="service-form-group">
                                <label for="{{ form.amount_usd.id_for_label }}">
                                    Top-up Amount USD
                                </label>

                                {{ form.amount_usd }}

                                {% for error in form.amount_usd.errors %}
                                    <div class="service-field-error">{{ error }}</div>
                                {% endfor %}

                                <div class="quick-amount-grid">
                                    <button type="button" class="quick-amount-btn" data-amount="10">USD 10</button>
                                    <button type="button" class="quick-amount-btn" data-amount="25">USD 25</button>
                                    <button type="button" class="quick-amount-btn" data-amount="50">USD 50</button>
                                    <button type="button" class="quick-amount-btn" data-amount="100">USD 100</button>
                                </div>
                            </div>


                            <div class="service-form-group">
                                <label class="form-label fw-bold mb-3">
                                    Payment Method
                                </label>

                                <div class="payment-method-list">

                                    <input
                                        class="btn-check"
                                        type="radio"
                                        name="payment_method"
                                        id="payStripe"
                                        value="stripe"
                                        {% if form.payment_method.value == "stripe" or not form.payment_method.value %}checked{% endif %}
                                    >

                                    <label class="payment-method-card stripe-card" for="payStripe">
                                        <div class="payment-method-left">
                                            <div class="payment-method-icon">
                                                <i class="bi bi-credit-card-2-front-fill"></i>
                                            </div>

                                            <div>
                                                <div class="payment-method-title">Stripe</div>
                                                <div class="payment-method-subtitle">
                                                    Pay securely with card
                                                </div>
                                            </div>
                                        </div>

                                        <div class="payment-method-right">
                                            <span class="payment-method-status">Available</span>
                                            <span class="payment-method-check">
                                                <i class="bi bi-check-circle-fill"></i>
                                            </span>
                                        </div>
                                    </label>


                                    <input
                                        class="btn-check"
                                        type="radio"
                                        name="payment_method"
                                        id="payPaypal"
                                        value="paypal"
                                        {% if form.payment_method.value == "paypal" %}checked{% endif %}
                                    >

                                    <label class="payment-method-card paypal-card" for="payPaypal">
                                        <div class="payment-method-left">
                                            <div class="payment-method-icon">
                                                <i class="bi bi-paypal"></i>
                                            </div>

                                            <div>
                                                <div class="payment-method-title">PayPal</div>
                                                <div class="payment-method-subtitle">
                                                    Pay securely with your PayPal account
                                                </div>
                                            </div>
                                        </div>

                                        <div class="payment-method-right">
                                            <span class="payment-method-status">Available</span>
                                            <span class="payment-method-check">
                                                <i class="bi bi-check-circle-fill"></i>
                                            </span>
                                        </div>
                                    </label>

                                </div>

                                {% for error in form.payment_method.errors %}
                                    <div class="service-field-error">{{ error }}</div>
                                {% endfor %}
                            </div>


                            <div class="service-note-box mb-4">
                                <strong>Important:</strong>
                                Wallet top-up payments are credited to your Service Partner wallet only after
                                payment confirmation. You can later use your wallet balance for eligible partner payments.
                            </div>

                            <button type="submit" class="btn service-wallet-submit w-100">
                                <i class="bi bi-lock-fill me-2"></i>
                                Continue to Secure Payment
                            </button>

                        </form>

                    </div>
                </div>
            </div>


            <div class="col-lg-4">

                <div class="service-wallet-card">
                    <div class="service-wallet-card-header">
                        <h3>Wallet Summary</h3>
                        <p>
                            Your wallet helps you manage future service partner payments more conveniently.
                        </p>
                    </div>

                    <div class="service-wallet-card-body">
                        <div class="service-wallet-balance-box">
                            <span>Available Balance</span>
                            <strong>USD {{ wallet.balance_usd|floatformat:2 }}</strong>
                        </div>

                        <div class="service-side-stat">
                            <span>Wallet Status</span>
                            <strong>
                                {% if wallet.is_active %}
                                    Active
                                {% else %}
                                    Inactive
                                {% endif %}
                            </strong>
                        </div>

                        <div class="service-side-stat">
                            <span>Profile Type</span>
                            <strong>Service Partner</strong>
                        </div>

                        <div class="service-side-stat">
                            <span>Minimum Top-up</span>
                            <strong>USD 5.00</strong>
                        </div>
                    </div>
                </div>


                <div class="service-wallet-card">
                    <div class="service-wallet-card-header">
                        <h3>What can wallet funds be used for?</h3>
                        <p>
                            Wallet funds can support eligible Service Partner payments.
                        </p>
                    </div>

                    <div class="service-wallet-card-body">
                        <ul class="mb-0 ps-3 text-muted" style="line-height: 1.85;">
                            <li>Service Partner featured or premium account fee.</li>
                            <li>Premium profile visibility upgrades.</li>
                            <li>Service-related platform charges where wallet usage is enabled.</li>
                            <li>Other eligible Service Partner payments approved by the platform.</li>
                        </ul>
                    </div>
                </div>


                <div class="service-wallet-card">
                    <div class="service-wallet-card-header">
                        <h3>Quick Links</h3>
                        <p>
                            Continue managing your Service Partner account.
                        </p>
                    </div>

                    <div class="service-wallet-card-body">
                        <div class="d-grid gap-2">
                            <a href="{% url 'service_partner_app:service_partner_payment_center' %}"
                               class="btn btn-dark rounded-pill fw-bold">
                                <i class="bi bi-wallet2 me-2"></i>
                                Payment Center
                            </a>

                            <a href="{% url 'service_partner_app:service_partner_dashboard' %}"
                               class="btn btn-outline-dark rounded-pill fw-bold">
                                <i class="bi bi-speedometer2 me-2"></i>
                                Dashboard
                            </a>
                        </div>
                    </div>
                </div>

            </div>

        </div>

    </div>
</section>


<script>
    document.addEventListener('DOMContentLoaded', function () {
        const amountInput = document.getElementById('{{ form.amount_usd.id_for_label }}');
        const quickButtons = document.querySelectorAll('.quick-amount-btn');

        quickButtons.forEach(function (button) {
            button.addEventListener('click', function () {
                const amount = button.dataset.amount || '';
                if (amountInput) {
                    amountInput.value = amount;
                    amountInput.focus();
                }
            });
        });
    });
</script>

{% endblock %}