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

{% block title %}Booking Detail | Host in Sri Lanka{% endblock %}

{% block content %}

<style>
    .hosting-booking-detail-page {
        min-height: 100vh;
        padding: 4rem 0 5rem;
        background:
            radial-gradient(circle at top left, rgba(255, 193, 7, 0.10), transparent 30%),
            radial-gradient(circle at top right, rgba(116, 49, 41, 0.10), transparent 32%),
            linear-gradient(180deg, #fffaf5 0%, #ffffff 48%, #fff7ed 100%);
        color: #2c1b17;
    }

    .hosting-detail-hero {
        border-radius: 36px;
        padding: 2.5rem 2.25rem;
        color: #ffffff;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.22), transparent 35%),
            linear-gradient(145deg, #2e1817 0%, #6d2e28 64%, #a3601b 100%);
        box-shadow: 0 30px 70px rgba(53, 27, 22, 0.20);
        margin-bottom: 2rem;
    }

    .hosting-detail-hero h1 {
        font-size: clamp(2.05rem, 4vw, 3.35rem);
        font-weight: 950;
        line-height: 1.06;
        letter-spacing: -0.05em;
        margin-bottom: 0.8rem;
    }

    .hosting-detail-hero p {
        color: rgba(255,255,255,0.84);
        line-height: 1.8;
        max-width: 860px;
        margin-bottom: 0;
    }

    .hosting-detail-card {
        border-radius: 32px;
        background: linear-gradient(145deg, #fffaf4 0%, #ffffff 100%);
        border: 1px solid rgba(124, 74, 50, 0.10);
        box-shadow: 0 18px 42px rgba(55,31,22,0.07);
        overflow: hidden;
        margin-bottom: 1.4rem;
    }

    .hosting-detail-card-header {
        padding: 1.45rem 1.55rem 1rem;
        border-bottom: 1px solid rgba(124, 74, 50, 0.10);
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.08), transparent 30%),
            linear-gradient(145deg, #fffaf4 0%, #ffffff 100%);
    }

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

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

    .hosting-detail-card-body {
        padding: 1.55rem;
    }

    .hosting-info-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.9rem;
    }

    .hosting-info-item {
        border-radius: 22px;
        padding: 1rem;
        background: #fff7e8;
        border: 1px solid #efd8b7;
    }

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

    .hosting-info-item strong {
        color: #38231d;
        font-weight: 900;
        word-break: break-word;
    }

    .hosting-total-box {
        border-radius: 28px;
        padding: 1.45rem;
        color: #ffffff;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.22), transparent 35%),
            linear-gradient(145deg, #2e1817 0%, #6d2e28 64%, #a3601b 100%);
        margin-bottom: 1rem;
    }

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

    .hosting-total-box strong {
        display: block;
        color: #ffffff;
        font-size: 2.15rem;
        font-weight: 950;
        line-height: 1;
    }

    .hosting-line {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.8rem 0;
        border-bottom: 1px solid #efd8b7;
        color: #6f4f3f;
    }

    .hosting-line:last-child {
        border-bottom: none;
    }

    .hosting-line strong {
        color: #38231d;
    }

    @media (max-width: 767.98px) {
        .hosting-detail-hero {
            padding: 2rem 1.35rem;
            border-radius: 30px;
        }

        .hosting-info-grid {
            grid-template-columns: 1fr;
        }
    }
</style>


<section class="hosting-booking-detail-page">
    <div class="container">

        <div class="hosting-detail-hero">
            <h1>{{ booking.get_event_type_display }}</h1>
            <p>
                Booking for {{ booking.venue_name_snapshot }}.
                Review event details, selected items, payment status, and host payout summary.
            </p>
        </div>


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

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

                <div class="hosting-detail-card">
                    <div class="hosting-detail-card-header">
                        <h2>Event & Client Details</h2>
                        <p>Information submitted by the guest or client.</p>
                    </div>

                    <div class="hosting-detail-card-body">
                        <div class="hosting-info-grid">
                            <div class="hosting-info-item">
                                <span>Client</span>
                                <strong>
                                    {% if booking.guest_profile %}
                                        {{ booking.guest_profile }}
                                    {% elif booking.hosting_client_profile %}
                                        {{ booking.hosting_client_profile.full_name }}
                                    {% elif booking.booked_by_user %}
                                        {{ booking.booked_by_user.get_username }}
                                    {% else %}
                                        Unknown Client
                                    {% endif %}
                                </strong>
                            </div>

                            <div class="hosting-info-item">
                                <span>Client Type</span>
                                <strong>{{ booking.get_client_type_display }}</strong>
                            </div>

                            <div class="hosting-info-item">
                                <span>Venue</span>
                                <strong>{{ booking.venue_name_snapshot }}</strong>
                            </div>

                            <div class="hosting-info-item">
                                <span>Event Date</span>
                                <strong>{{ booking.preferred_event_date }}</strong>
                            </div>

                            <div class="hosting-info-item">
                                <span>Start Time</span>
                                <strong>{{ booking.preferred_start_time|default:"Flexible / Not specified" }}</strong>
                            </div>

                            <div class="hosting-info-item">
                                <span>Guests</span>
                                <strong>{{ booking.number_of_guests }}</strong>
                            </div>

                            <div class="hosting-info-item">
                                <span>Status</span>
                                <strong>{{ booking.get_status_display }}</strong>
                            </div>

                            <div class="hosting-info-item">
                                <span>Payment Status</span>
                                <strong>{{ booking.get_payment_status_display }}</strong>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="hosting-detail-card">
                    <div class="hosting-detail-card-header">
                        <h3>Selected Items</h3>
                        <p>Package, meal plan, and add-on services.</p>
                    </div>

                    <div class="hosting-detail-card-body">
                        <div class="hosting-line">
                            <span>Event Package</span>
                            <strong>
                                {% if booking.selected_package %}
                                    {{ booking.package_title_snapshot }} — USD {{ booking.package_amount_snapshot_usd|floatformat:2 }}
                                {% else %}
                                    Not selected
                                {% endif %}
                            </strong>
                        </div>

                        <div class="hosting-line">
                            <span>Meal Plan</span>
                            <strong>
                                {% if booking.selected_meal_plan %}
                                    {{ booking.meal_plan_title_snapshot }} — USD {{ booking.meal_amount_snapshot_usd|floatformat:2 }}
                                {% else %}
                                    Not selected
                                {% endif %}
                            </strong>
                        </div>

                        <div class="hosting-line">
                            <span>Add-ons</span>
                            <strong>USD {{ booking.add_on_amount_snapshot_usd|floatformat:2 }}</strong>
                        </div>

                        {% if selected_add_ons %}
                            <div class="mt-3">
                                {% for item in selected_add_ons %}
                                    <div class="hosting-info-item mb-2">
                                        <span>{{ item.add_on_title_snapshot }}</span>
                                        <strong>
                                            {{ item.quantity }} × USD {{ item.unit_price_snapshot_usd|floatformat:2 }}
                                            = USD {{ item.subtotal_snapshot_usd|floatformat:2 }}
                                        </strong>
                                    </div>
                                {% endfor %}
                            </div>
                        {% endif %}
                    </div>
                </div>


                {% if booking.occasion_title or booking.occasion_note or booking.special_requests %}
                    <div class="hosting-detail-card">
                        <div class="hosting-detail-card-header">
                            <h3>Occasion Notes</h3>
                            <p>Notes and special requirements from the client.</p>
                        </div>

                        <div class="hosting-detail-card-body">
                            {% if booking.occasion_title %}
                                <div class="hosting-info-item mb-2">
                                    <span>Occasion Title</span>
                                    <strong>{{ booking.occasion_title }}</strong>
                                </div>
                            {% endif %}

                            {% if booking.occasion_note %}
                                <div class="hosting-info-item mb-2">
                                    <span>Occasion Note</span>
                                    <strong style="white-space: pre-line;">{{ booking.occasion_note }}</strong>
                                </div>
                            {% endif %}

                            {% if booking.special_requests %}
                                <div class="hosting-info-item">
                                    <span>Special Requests</span>
                                    <strong style="white-space: pre-line;">{{ booking.special_requests }}</strong>
                                </div>
                            {% endif %}
                        </div>
                    </div>
                {% endif %}

            </div>


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

                <div class="hosting-detail-card">
                    <div class="hosting-detail-card-header">
                        <h3>Financial Summary</h3>
                        <p>Booking amount and host earning calculation.</p>
                    </div>

                    <div class="hosting-detail-card-body">
                        <div class="hosting-total-box">
                            <span>Total Booking Amount</span>
                            <strong>USD {{ booking.total_amount_usd|floatformat:2 }}</strong>
                        </div>

                        <div class="hosting-line">
                            <span>Platform Commission</span>
                            <strong>USD {{ booking.ensolanka_commission_usd|floatformat:2 }}</strong>
                        </div>

                        <div class="hosting-line">
                            <span>Commission Rate</span>
                            <strong>{{ booking.commission_rate_percent|floatformat:2 }}%</strong>
                        </div>

                        <div class="hosting-line">
                            <span>Host Net Amount</span>
                            <strong>USD {{ booking.host_net_amount_usd|floatformat:2 }}</strong>
                        </div>

                        {% if booking.payable_item %}
                            <div class="hosting-line">
                                <span>Payment Reference</span>
                                <strong>{{ booking.payment_reference_code }}</strong>
                            </div>
                        {% endif %}
                    </div>
                </div>


                <div class="d-grid gap-2">
                    <a href="{% url 'hosting_app:host_booking_list' %}"
                       class="btn btn-outline-dark rounded-pill fw-bold">
                        <i class="bi bi-arrow-left-circle me-2"></i>
                        Back to Bookings
                    </a>

                    <a href="{% url 'hosting_app:host_payment_center' %}"
                       class="btn btn-dark rounded-pill fw-bold">
                        <i class="bi bi-wallet2 me-2"></i>
                        Payment Center
                    </a>
                </div>

            </div>

        </div>

    </div>
</section>

{% endblock %}