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

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

{% block content %}

<style>
    /* =========================================================
       HOSTING CLIENT DASHBOARD — HOSTING APP THEME
    ========================================================= */

    .hosting-client-dashboard-page {
        min-height: 100vh;
        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;
        padding: 4rem 0 5rem;
    }

    .hosting-client-hero {
        border-radius: 36px;
        padding: 2.7rem 2.35rem;
        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;
        position: relative;
        overflow: hidden;
    }

    .hosting-client-hero::before {
        content: "";
        position: absolute;
        width: 260px;
        height: 260px;
        border-radius: 999px;
        right: -80px;
        top: -80px;
        background: rgba(255, 193, 7, 0.16);
        pointer-events: none;
    }

    .hosting-client-hero > * {
        position: relative;
        z-index: 2;
    }

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

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

    .hosting-client-hero p {
        color: rgba(255, 255, 255, 0.84);
        line-height: 1.8;
        max-width: 900px;
        margin-bottom: 1.4rem;
    }

    .hosting-client-hero-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.85rem;
    }

    .hosting-client-hero-actions .btn {
        border-radius: 999px;
        min-height: 50px;
        font-weight: 950;
        padding: 0.8rem 1.3rem;
    }

    .client-btn-gold {
        background: linear-gradient(135deg, #ffc83f, #df9219);
        color: #26160d;
        border: none;
        font-weight: 950 !important;
        box-shadow: 0 18px 34px rgba(223, 146, 25, 0.30);
        transition: all 0.22s ease;
    }

    .client-btn-gold:hover,
    .client-btn-gold:focus {
        background: linear-gradient(135deg, #2e1817, #6d2e28);
        color: #ffffff !important;
        transform: translateY(-2px);
        box-shadow: 0 22px 42px rgba(54, 28, 23, 0.28);
    }

    .client-btn-glass {
        background: rgba(255, 255, 255, 0.10);
        color: #ffffff;
        border: 1px solid rgba(255, 255, 255, 0.34);
        backdrop-filter: blur(10px);
    }

    .client-btn-glass:hover {
        background: rgba(255, 255, 255, 0.17);
        color: #ffffff;
    }

    .client-alert-card {
        border-radius: 28px;
        padding: 1.35rem;
        background: #fffbeb;
        border: 1px solid #fde68a;
        box-shadow: 0 14px 32px rgba(55, 31, 22, 0.06);
        margin-bottom: 1.5rem;
    }

    .client-alert-card h3 {
        color: #38231d;
        font-weight: 950;
        margin-bottom: 0.55rem;
    }

    .client-credential-grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0.8rem;
        margin-top: 1rem;
    }

    .client-credential-item {
        border-radius: 20px;
        background: #ffffff;
        border: 1px solid #efd8b7;
        padding: 0.95rem;
    }

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

    .client-credential-item strong {
        color: #38231d;
        font-weight: 950;
        word-break: break-word;
    }

    .client-stats-grid {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .client-stat-card {
        border-radius: 26px;
        padding: 1.15rem;
        background: linear-gradient(145deg, #fffaf4 0%, #ffffff 100%);
        border: 1px solid rgba(124, 74, 50, 0.10);
        box-shadow: 0 14px 30px rgba(55, 31, 22, 0.06);
        position: relative;
        overflow: hidden;
    }

    .client-stat-card::before {
        content: "";
        position: absolute;
        top: -50px;
        right: -50px;
        width: 120px;
        height: 120px;
        border-radius: 999px;
        background: rgba(255, 193, 7, 0.11);
        pointer-events: none;
    }

    .client-stat-card > * {
        position: relative;
        z-index: 2;
    }

    .client-stat-icon {
        width: 46px;
        height: 46px;
        border-radius: 16px;
        background: #fff0d6;
        color: #a75e17;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
        margin-bottom: 0.75rem;
    }

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

    .client-stat-card strong {
        color: #38231d;
        font-size: 1.45rem;
        font-weight: 950;
    }

    .client-dashboard-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;
    }

    .client-dashboard-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%);
    }

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

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

    .client-dashboard-card-body {
        padding: 1.55rem;
    }

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

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

    .client-profile-item 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-item strong {
        color: #38231d;
        font-weight: 900;
        word-break: break-word;
    }

    .client-booking-card {
        border-radius: 26px;
        background: #ffffff;
        border: 1px solid rgba(124, 74, 50, 0.10);
        box-shadow: 0 12px 28px rgba(55, 31, 22, 0.05);
        padding: 1.15rem;
        margin-bottom: 0.9rem;
    }

    .client-booking-title {
        color: #38231d;
        font-weight: 950;
        font-size: 1.05rem;
        margin-bottom: 0.45rem;
    }

    .client-booking-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 0.45rem;
        margin-bottom: 0.85rem;
    }

    .client-booking-chip {
        display: inline-flex;
        align-items: center;
        gap: 0.32rem;
        border-radius: 999px;
        padding: 0.34rem 0.58rem;
        background: #fff7e8;
        border: 1px solid #efd8b7;
        color: #6f4f3f;
        font-size: 0.75rem;
        font-weight: 850;
    }

    .client-booking-chip.paid {
        background: #ecfdf5;
        border-color: #a7f3d0;
        color: #047857;
    }

    .client-booking-chip.due {
        background: #fffbeb;
        border-color: #fde68a;
        color: #92400e;
    }

    .client-empty-card {
        border-radius: 28px;
        padding: 2.4rem 1.4rem;
        text-align: center;
        background: #ffffff;
        border: 1px solid rgba(124, 74, 50, 0.10);
    }

    .client-empty-icon {
        width: 78px;
        height: 78px;
        border-radius: 28px;
        background: #fff0d6;
        color: #a75e17;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 2.2rem;
        margin-bottom: 1rem;
    }

    .client-empty-card h3 {
        color: #38231d;
        font-weight: 950;
    }

    .client-empty-card p {
        color: #78625a;
        line-height: 1.7;
        max-width: 620px;
        margin-left: auto;
        margin-right: auto;
    }

    .client-quick-actions {
        display: grid;
        gap: 0.8rem;
    }

    .client-quick-actions .btn {
        border-radius: 999px;
        min-height: 48px;
        font-weight: 900;
    }

    @media (max-width: 1199.98px) {
        .client-stats-grid {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }

        .client-credential-grid {
            grid-template-columns: 1fr;
        }
    }

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

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

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

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

        .client-stats-grid,
        .client-profile-grid {
            grid-template-columns: 1fr;
        }

        .client-dashboard-card-header,
        .client-dashboard-card-body {
            padding-left: 1.15rem;
            padding-right: 1.15rem;
        }
    }

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


<section class="hosting-client-dashboard-page">
    <div class="container">

        <!-- HERO -->
        <div class="hosting-client-hero">
            <span class="hosting-client-kicker">
                <i class="bi bi-speedometer2"></i>
                Hosting Client Dashboard
            </span>

            <h1>
                Welcome, {{ hosting_client_profile.full_name }}
            </h1>

            <p>
                Manage your hosting experience bookings, review payment status, browse venues,
                and continue planning celebrations, romantic events, private dining, and custom experiences.
            </p>

            <div class="hosting-client-hero-actions">
                <a href="{% url 'hosting_app:public_host_venue_list' %}"
                   class="btn client-btn-gold">
                    <i class="bi bi-search-heart-fill me-2"></i>
                    Browse Host Venues
                </a>

                <a href="{% url 'hosting_app:hosting_client_profile_page' %}"
                    class="btn client-btn-glass">
                    <i class="bi bi-person-circle me-2"></i>
                    My Profile
                </a>

                <a href="{% url 'hosting_app:hosting_client_payment_center' %}"
                   class="btn client-btn-glass">
                    <i class="bi bi-wallet2 me-2"></i>
                    Payment Center
                </a>
            </div>
        </div>


        <!-- FIRST-TIME ACCOUNT CREDENTIALS -->
        {% if username and password %}
            <div class="client-alert-card">
                <h3>
                    <i class="bi bi-key-fill me-2"></i>
                    Your New Account Details
                </h3>

                <p class="mb-0 text-muted">
                    Please save these details now. For security, the password is shown only once.
                </p>

                <div class="client-credential-grid">
                    <div class="client-credential-item">
                        <span>Role</span>
                        <strong>{{ account_role|default:"Hosting Client" }}</strong>
                    </div>

                    <div class="client-credential-item">
                        <span>Username</span>
                        <strong>{{ username }}</strong>
                    </div>

                    <div class="client-credential-item">
                        <span>Password</span>
                        <strong>{{ password }}</strong>
                    </div>

                    {% if new_account_email %}
                        <div class="client-credential-item">
                            <span>Email</span>
                            <strong>{{ new_account_email }}</strong>
                        </div>
                    {% endif %}
                </div>
            </div>
        {% endif %}


        <!-- STATS -->
        <div class="client-stats-grid">

            <div class="client-stat-card">
                <div class="client-stat-icon">
                    <i class="bi bi-calendar-heart-fill"></i>
                </div>
                <span>Total Bookings</span>
                <strong>{{ bookings|length }}</strong>
            </div>

            <div class="client-stat-card">
                <div class="client-stat-icon">
                    <i class="bi bi-wallet2"></i>
                </div>
                <span>Payment Center</span>
                <strong>Ready</strong>
            </div>

            <div class="client-stat-card">
                <div class="client-stat-icon">
                    <i class="bi bi-person-check-fill"></i>
                </div>
                <span>Client Type</span>
                <strong>{{ hosting_client_profile.get_client_type_display }}</strong>
            </div>

            <div class="client-stat-card">
                <div class="client-stat-icon">
                    <i class="bi bi-shield-check"></i>
                </div>
                <span>Account Status</span>
                <strong>
                    {% if hosting_client_profile.is_active %}
                        Active
                    {% else %}
                        Inactive
                    {% endif %}
                </strong>
            </div>

        </div>


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

            <!-- MAIN CONTENT -->
            <div class="col-lg-8">

                <!-- RECENT BOOKINGS -->
                <div class="client-dashboard-card">
                    <div class="client-dashboard-card-header">
                        <h2>Recent Hosting Bookings</h2>
                        <p>
                            View your latest hosting experience bookings and continue to review or payment where needed.
                        </p>
                    </div>

                    <div class="client-dashboard-card-body">

                        {% if bookings %}
                            {% for booking in bookings %}
                                <div class="client-booking-card">

                                    <div class="d-flex flex-wrap justify-content-between gap-3 align-items-start">
                                        <div>
                                            <h3 class="client-booking-title">
                                                {{ booking.get_event_type_display }} — {{ booking.venue_name_snapshot }}
                                            </h3>

                                            <div class="client-booking-meta">
                                                <span class="client-booking-chip">
                                                    <i class="bi bi-calendar-event"></i>
                                                    {{ booking.preferred_event_date }}
                                                </span>

                                                <span class="client-booking-chip">
                                                    <i class="bi bi-people-fill"></i>
                                                    {{ booking.number_of_guests }} guests
                                                </span>

                                                <span class="client-booking-chip {% if booking.payment_status == 'paid' %}paid{% elif booking.payment_status == 'due' or booking.payment_status == 'unpaid' %}due{% endif %}">
                                                    <i class="bi bi-credit-card-fill"></i>
                                                    {{ booking.get_payment_status_display }}
                                                </span>

                                                <span class="client-booking-chip">
                                                    <i class="bi bi-list-check"></i>
                                                    {{ booking.get_status_display }}
                                                </span>
                                            </div>

                                            <p class="text-muted mb-0">
                                                Total:
                                                <strong>USD {{ booking.total_amount_usd|floatformat:2 }}</strong>
                                            </p>
                                        </div>

                                        <div class="d-flex flex-column gap-2">
                                            <a href="{% url 'hosting_app:local_client_booking_review' booking.id %}"
                                               class="btn btn-outline-dark rounded-pill fw-bold">
                                                Review
                                                <i class="bi bi-arrow-right ms-2"></i>
                                            </a>

                                            {% if booking.payable_item and booking.payment_status != 'paid' %}
                                                <a href="{% url 'hosting_app:hosting_client_payment_center' %}"
                                                   class="btn btn-dark rounded-pill fw-bold">
                                                    Pay Now
                                                </a>
                                            {% endif %}
                                        </div>
                                    </div>

                                </div>
                            {% endfor %}
                        {% else %}
                            <div class="client-empty-card">
                                <div class="client-empty-icon">
                                    <i class="bi bi-calendar-heart-fill"></i>
                                </div>

                                <h3>No bookings yet</h3>

                                <p>
                                    You have not created a hosting experience booking yet.
                                    Browse available host venues and start planning your event.
                                </p>

                                <a href="{% url 'hosting_app:public_host_venue_list' %}"
                                   class="btn client-btn-gold">
                                    <i class="bi bi-search-heart-fill me-2"></i>
                                    Browse Venues
                                </a>
                            </div>
                        {% endif %}

                    </div>
                </div>

            </div>


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

                <!-- PROFILE SUMMARY -->
                <div class="client-dashboard-card">
                    <div class="client-dashboard-card-header">
                        <h3>Client Profile</h3>
                        <p>
                            Your contact details used for hosting bookings.
                        </p>
                    </div>

                    <div class="client-dashboard-card-body">
                        <div class="client-profile-grid">

                            <div class="client-profile-item">
                                <span>Full Name</span>
                                <strong>{{ hosting_client_profile.full_name }}</strong>
                            </div>

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

                            <div class="client-profile-item">
                                <span>Phone</span>
                                <strong>{{ hosting_client_profile.phone_number }}</strong>
                            </div>

                            <div class="client-profile-item">
                                <span>WhatsApp</span>
                                <strong>
                                    {{ hosting_client_profile.whatsapp_number|default:"Not provided" }}
                                </strong>
                            </div>

                            <div class="client-profile-item">
                                <span>Country</span>
                                <strong>{{ hosting_client_profile.country|default:"Sri Lanka" }}</strong>
                            </div>

                            <div class="client-profile-item">
                                <span>City</span>
                                <strong>{{ hosting_client_profile.city|default:"Not provided" }}</strong>
                            </div>

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


                <!-- QUICK ACTIONS -->
                <div class="client-dashboard-card">
                    <div class="client-dashboard-card-header">
                        <h3>Quick Actions</h3>
                        <p>
                            Continue managing your hosting client account.
                        </p>
                    </div>

                    <div class="client-dashboard-card-body">
                        <div class="client-quick-actions">

                            <a href="{% url 'hosting_app:public_host_venue_list' %}"
                               class="btn client-btn-gold">
                                <i class="bi bi-search-heart-fill me-2"></i>
                                Browse Host Venues
                            </a>

                            <a href="{% url 'hosting_app:hosting_client_profile_page' %}"
                                class="btn btn-outline-warning">
                                <i class="bi bi-person-circle me-2"></i>
                                My Profile
                            </a>

                            <a href="{% url 'hosting_app:hosting_client_payment_center' %}"
                               class="btn btn-outline-dark">
                                <i class="bi bi-wallet2 me-2"></i>
                                Payment Center
                            </a>

                            <a href="{% url 'hosting_app:home_hosting' %}"
                               class="btn btn-outline-secondary">
                                <i class="bi bi-house-heart-fill me-2"></i>
                                Hosting Home
                            </a>

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


                <!-- PROCESS INFO -->
                <div class="client-dashboard-card">
                    <div class="client-dashboard-card-header">
                        <h3>Booking Process</h3>
                        <p>
                            How your local hosting booking works.
                        </p>
                    </div>

                    <div class="client-dashboard-card-body">
                        <ul class="mb-0 ps-3 text-muted" style="line-height: 1.85;">
                            <li>Select a public host venue.</li>
                            <li>Choose package, meal plan, add-ons, date, and guest count.</li>
                            <li>Review the booking and continue to payment center.</li>
                            <li>After payment, your booking becomes confirmed for coordination.</li>
                        </ul>
                    </div>
                </div>

            </div>

        </div>

    </div>
</section>

{% endblock %}