{% extends 'hosting_app/base_hosting.html' %}
{% load static %}

{% block title %}Hosting Client Payment Checkout | Host in Sri Lanka{% endblock %}

{% block content %}

<style>
    /* =========================================================
       HOSTING CLIENT PAYMENT CHECKOUT — PREMIUM
    ========================================================= */

    .hosting-checkout-page {
        min-height: 100vh;
        padding: 4rem 0 5rem;
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.12), transparent 30%),
            radial-gradient(circle at top right, rgba(116, 49, 41, 0.10), transparent 32%),
            linear-gradient(180deg, #fffaf5 0%, #fff4e8 42%, #ffffff 100%);
    }

    .hosting-checkout-hero {
        position: relative;
        overflow: hidden;
        border-radius: 38px;
        padding: 2.6rem 2.4rem;
        margin-bottom: 2rem;
        color: #ffffff;
        background:
            radial-gradient(circle at top right, rgba(255, 211, 107, 0.22), transparent 32%),
            linear-gradient(135deg, #2d1716 0%, #743129 56%, #a7601b 100%);
        box-shadow: 0 30px 68px rgba(58, 30, 24, 0.20);
    }

    .hosting-checkout-hero::before {
        content: "";
        position: absolute;
        top: -110px;
        right: -85px;
        width: 300px;
        height: 300px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.07);
        pointer-events: none;
    }

    .hosting-checkout-hero::after {
        content: "";
        position: absolute;
        bottom: -150px;
        left: -110px;
        width: 360px;
        height: 360px;
        border-radius: 50%;
        background: rgba(255, 193, 7, 0.10);
        pointer-events: none;
    }

    .hosting-checkout-hero-inner {
        position: relative;
        z-index: 2;
    }

    .hosting-checkout-kicker {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.52rem 1rem;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.14);
        border: 1px solid rgba(255, 255, 255, 0.22);
        color: #ffe7aa;
        font-size: 0.84rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 1rem;
    }

    .hosting-checkout-hero h1 {
        font-size: clamp(2.15rem, 4vw, 3.45rem);
        font-weight: 950;
        line-height: 1.1;
        letter-spacing: -0.045em;
        margin-bottom: 0.75rem;
    }

    .hosting-checkout-hero p {
        max-width: 850px;
        margin-bottom: 0;
        color: rgba(255, 255, 255, 0.88);
        font-size: 1.03rem;
        line-height: 1.8;
    }

    .hosting-checkout-hero-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.85rem;
        margin-top: 1.6rem;
    }

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

    .hosting-btn-gold {
        background: #ffc107;
        color: #2d1716;
        border: none;
        font-weight: 900;
    }

    .hosting-btn-gold:hover {
        background: #ffe082;
        color: #2d1716;
        transform: translateY(-1px);
    }

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

    .hosting-btn-light-outline:hover {
        background: #ffffff;
        color: #2d1716;
    }

    .hosting-checkout-card {
        border-radius: 34px;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid rgba(239, 226, 211, 0.95);
        box-shadow: 0 24px 56px rgba(58, 30, 24, 0.10);
        overflow: hidden;
        margin-bottom: 1.5rem;
    }

    .hosting-checkout-card-header {
        padding: 1.55rem 1.7rem 1.1rem;
        border-bottom: 1px solid #efe2d3;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.08), transparent 28%),
            linear-gradient(145deg, #fffaf4 0%, #ffffff 100%);
    }

    .hosting-checkout-card-header h3,
    .hosting-checkout-card-header h4 {
        color: #38231d;
        font-weight: 950;
        margin-bottom: 0.35rem;
    }

    .hosting-checkout-card-header p {
        color: #78625a;
        line-height: 1.65;
        margin-bottom: 0;
    }

    .hosting-checkout-card-body {
        padding: 1.65rem 1.7rem;
    }

    .hosting-checkout-table {
        margin-bottom: 0;
    }

    .hosting-checkout-table thead th {
        color: #6f4f3f;
        font-size: 0.78rem;
        font-weight: 950;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        border-bottom-color: #efe2d3;
        padding-top: 0;
    }

    .hosting-checkout-table tbody td {
        color: #38231d;
        vertical-align: middle;
        border-bottom-color: #f3e7d8;
        padding-top: 1rem;
        padding-bottom: 1rem;
    }

    .hosting-checkout-table tfoot td {
        border-top: 2px solid #eadbc9;
        color: #38231d;
        font-size: 1.05rem;
        padding-top: 1.1rem;
    }

    .checkout-item-title {
        color: #38231d;
        font-weight: 950;
        margin-bottom: 0.2rem;
    }

    .checkout-item-desc {
        color: #78625a;
        font-size: 0.88rem;
        line-height: 1.55;
    }

    .checkout-item-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        border-radius: 999px;
        padding: 0.34rem 0.62rem;
        background: #fff7e8;
        border: 1px solid #efd8b7;
        color: #6f4f3f;
        font-size: 0.76rem;
        font-weight: 850;
        white-space: nowrap;
    }

    .checkout-total-panel {
        border-radius: 28px;
        padding: 1.35rem;
        color: #ffffff;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.22), transparent 35%),
            linear-gradient(135deg, #2d1716, #743129);
        box-shadow: 0 18px 34px rgba(58, 30, 24, 0.16);
        margin-bottom: 1.2rem;
    }

    .checkout-total-panel span {
        display: block;
        color: rgba(255, 255, 255, 0.74);
        font-size: 0.82rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.35rem;
    }

    .checkout-total-panel strong {
        color: #ffffff;
        font-size: 2rem;
        font-weight: 950;
        line-height: 1;
    }

    .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 #eadbc9;
        border-radius: 1.15rem;
        padding: 0.95rem 1rem;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.05), transparent 32%),
            #ffffff;
        cursor: pointer;
        transition: all 0.2s ease-in-out;
        min-height: 78px;
    }

    .payment-method-card:hover {
        border-color: #d59a43;
        box-shadow: 0 0.45rem 1rem rgba(58, 30, 24, 0.08);
        transform: translateY(-1px);
    }

    .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.25rem;
        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: #38231d;
        line-height: 1.2;
    }

    .payment-method-subtitle {
        font-size: 0.9rem;
        color: #78625a;
        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: 800;
        color: #047857;
        background: #ecfdf5;
        border: 1px solid #a7f3d0;
        border-radius: 999px;
        padding: 0.3rem 0.65rem;
    }

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

    .btn-check:checked + .payment-method-card {
        border-color: #a75e17;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.10), transparent 32%),
            #ffffff;
        box-shadow: 0 0 0 3px rgba(167, 94, 23, 0.13);
    }

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

    .checkout-submit-btn {
        border-radius: 999px;
        min-height: 52px;
        background: linear-gradient(135deg, #ffc107, #df9219);
        color: #2d1716;
        border: none;
        font-weight: 950;
        box-shadow: 0 16px 32px rgba(223, 146, 25, 0.24);
    }

    .checkout-submit-btn:hover {
        background: linear-gradient(135deg, #2d1716, #743129);
        color: #ffffff;
        transform: translateY(-1px);
        box-shadow: 0 20px 38px rgba(58, 30, 24, 0.22);
    }

    .checkout-back-btn {
        border-radius: 999px;
        min-height: 48px;
        font-weight: 850;
    }

    .checkout-note {
        border-radius: 24px;
        padding: 1rem;
        background: #fffbeb;
        border: 1px solid #fde68a;
        color: #92400e;
        line-height: 1.65;
        font-weight: 750;
    }

    .client-profile-box {
        border-radius: 24px;
        padding: 1rem;
        background: #fff7e8;
        border: 1px solid #efd8b7;
        margin-bottom: 0.8rem;
    }

    .client-profile-box span {
        display: block;
        color: #8b6550;
        font-size: 0.76rem;
        font-weight: 950;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.35rem;
    }

    .client-profile-box strong {
        color: #38231d;
        font-weight: 900;
        word-break: break-word;
    }

    @media (max-width: 767.98px) {
        .hosting-checkout-page {
            padding-top: 2.8rem;
        }

        .hosting-checkout-hero {
            padding: 2rem 1.35rem;
            border-radius: 30px;
        }

        .hosting-checkout-hero-actions {
            flex-direction: column;
            align-items: stretch;
        }

        .hosting-checkout-hero-actions .btn {
            width: 100%;
        }

        .hosting-checkout-card-header,
        .hosting-checkout-card-body {
            padding-left: 1.15rem;
            padding-right: 1.15rem;
        }

        .payment-method-card {
            padding: 0.9rem;
            min-height: 74px;
        }

        .payment-method-icon {
            width: 42px;
            height: 42px;
            font-size: 1.1rem;
        }

        .payment-method-status {
            display: none;
        }
    }

    @media (max-width: 575.98px) {
        .hosting-checkout-page > .container {
            padding-left: 1.25rem !important;
            padding-right: 1.25rem !important;
        }
    }
</style>


<section class="hosting-checkout-page">
    <div class="container">

        <!-- HERO -->
        <div class="hosting-checkout-hero">
            <div class="hosting-checkout-hero-inner">
                <span class="hosting-checkout-kicker">
                    <i class="bi bi-credit-card-2-front-fill"></i>
                    Hosting Client Checkout
                </span>

                <h1>Review & continue to payment</h1>

                <p>
                    Review the selected hosting client payable items, confirm the total amount,
                    and choose Stripe or PayPal to continue securely.
                </p>

                <div class="hosting-checkout-hero-actions">
                    <a href="{% url 'hosting_app:hosting_client_payment_center' %}"
                       class="btn hosting-btn-light-outline">
                        <i class="bi bi-arrow-left-circle me-2"></i>
                        Back to Payment Center
                    </a>

                    <a href="{% url 'hosting_app:hosting_client_dashboard' %}"
                       class="btn hosting-btn-gold">
                        <i class="bi bi-speedometer2 me-2"></i>
                        Client Dashboard
                    </a>
                </div>
            </div>
        </div>


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

            <!-- SELECTED ITEMS -->
            <div class="col-lg-8">

                <div class="hosting-checkout-card">
                    <div class="hosting-checkout-card-header">
                        <h3>Selected Payable Items</h3>
                        <p>
                            These are the payment items you selected from your Hosting Client Payment Center.
                        </p>
                    </div>

                    <div class="hosting-checkout-card-body">
                        <div class="table-responsive">
                            <table class="table hosting-checkout-table align-middle">
                                <thead>
                                    <tr>
                                        <th>Payment Item</th>
                                        <th>Type</th>
                                        <th class="text-end">Amount</th>
                                    </tr>
                                </thead>

                                <tbody>
                                    {% for item in payable_items %}
                                        <tr>
                                            <td>
                                                <div class="checkout-item-title">
                                                    {{ item.title }}
                                                </div>

                                                {% if item.description %}
                                                    <div class="checkout-item-desc">
                                                        {{ item.description }}
                                                    </div>
                                                {% endif %}

                                                {% if item.reference_code %}
                                                    <div class="mt-2">
                                                        <span class="checkout-item-chip">
                                                            <i class="bi bi-hash"></i>
                                                            {{ item.reference_code }}
                                                        </span>
                                                    </div>
                                                {% endif %}
                                            </td>

                                            <td>
                                                <span class="checkout-item-chip">
                                                    <i class="bi bi-tag-fill"></i>
                                                    {{ item.get_payment_for_display }}
                                                </span>
                                            </td>

                                            <td class="text-end fw-bold">
                                                USD {{ item.amount_usd|floatformat:2 }}
                                            </td>
                                        </tr>
                                    {% endfor %}
                                </tbody>

                                <tfoot>
                                    <tr>
                                        <td colspan="2" class="text-end fw-bold">
                                            Total Payment
                                        </td>
                                        <td class="text-end fw-bold">
                                            USD {{ total_amount|floatformat:2 }}
                                        </td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>


                <div class="hosting-checkout-card">
                    <div class="hosting-checkout-card-header">
                        <h3>Important Payment Note</h3>
                        <p>
                            Your booking will be marked as paid after successful checkout.
                        </p>
                    </div>

                    <div class="hosting-checkout-card-body">
                        <div class="checkout-note">
                            Stripe and PayPal checkout starter views are connected from this page.
                            Final payment transaction creation and gateway API handling can be completed
                            later using your shared project payment logic.
                        </div>
                    </div>
                </div>

            </div>


            <!-- PAYMENT METHOD -->
            <div class="col-lg-4">

                <div class="hosting-checkout-card">
                    <div class="hosting-checkout-card-header">
                        <h4>Payment Summary</h4>
                        <p>
                            Confirm the total and choose your preferred payment method.
                        </p>
                    </div>

                    <div class="hosting-checkout-card-body">

                        <div class="checkout-total-panel">
                            <span>Total Payment</span>
                            <strong>USD {{ total_amount|floatformat:2 }}</strong>
                        </div>

                        {% if hosting_client_profile %}
                            <div class="client-profile-box">
                                <span>Client</span>
                                <strong>{{ hosting_client_profile.full_name }}</strong>
                            </div>

                            <div class="client-profile-box">
                                <span>Email</span>
                                <strong>{{ hosting_client_profile.email }}</strong>
                            </div>
                        {% endif %}

                        <form method="post"
                              action="{% url 'hosting_app:hosting_client_payment_checkout_pay' %}">
                            {% csrf_token %}

                            {% for item in payable_items %}
                                <input type="hidden" name="selected_items" value="{{ item.id }}">
                            {% endfor %}

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

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

                                    <!-- Stripe -->
                                    <input
                                        class="btn-check"
                                        type="radio"
                                        name="payment_method"
                                        id="payStripe"
                                        value="stripe"
                                        checked
                                    >

                                    <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>


                                    <!-- PayPal -->
                                    <input
                                        class="btn-check"
                                        type="radio"
                                        name="payment_method"
                                        id="payPaypal"
                                        value="paypal"
                                    >

                                    <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>
                            </div>
                            <!-- Secure Checkout Trust Badge -->
                            <div class="checkout-secure-trust-wrap">
                                <div class="checkout-secure-trust-badge">
                                    <img src="{% static 'expat_life/images/secure_https_badge.png' %}"
                                        alt="Secure HTTPS SSL TLS Protected"
                                        class="checkout-secure-trust-img">

                                    <div class="checkout-secure-trust-text">
                                        <strong>Secure Checkout</strong>
                                        <span>Your payment is protected through SSL/TLS encrypted connection.</span>
                                    </div>
                                </div>
                            </div>
                            <button type="submit" class="btn checkout-submit-btn w-100">
                                <i class="bi bi-lock-fill me-2"></i>
                                Continue to Payment
                            </button>

                            <a href="{% url 'hosting_app:hosting_client_payment_center' %}"
                               class="btn btn-outline-secondary checkout-back-btn w-100 mt-2">
                                <i class="bi bi-arrow-left-circle me-2"></i>
                                Back to Payment Center
                            </a>

                        </form>

                    </div>
                </div>

            </div>

        </div>

    </div>
</section>

{% endblock %}