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

{% block title %}Manage Gallery | {{ venue.venue_name }}{% endblock %}

{% block content %}

<style>
    /* =========================================================
       HOST VENUE GALLERY MANAGE — PREMIUM DASHBOARD STYLE
    ========================================================= */

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

    .hosting-gallery-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-gallery-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-gallery-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-gallery-hero-inner {
        position: relative;
        z-index: 2;
    }

    .hosting-gallery-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-gallery-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-gallery-hero p {
        max-width: 850px;
        margin-bottom: 0;
        color: rgba(255, 255, 255, 0.88);
        font-size: 1.03rem;
        line-height: 1.8;
    }

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

    .hosting-gallery-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;
    }

    .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-gallery-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-gallery-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(180deg, #ffffff 0%, #fffaf5 100%);
    }

    .hosting-gallery-card-header h2,
    .hosting-gallery-card-header h3 {
        color: #2d1716;
        font-weight: 950;
        margin-bottom: 0.35rem;
    }

    .hosting-gallery-card-header p {
        color: #7a655d;
        margin-bottom: 0;
        line-height: 1.65;
    }

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

    .hosting-form-group {
        margin-bottom: 1.15rem;
    }

    .hosting-form-group label {
        display: block;
        color: #2d1716;
        font-weight: 850;
        margin-bottom: 0.45rem;
    }

    .hosting-form-group input,
    .hosting-form-group textarea,
    .hosting-form-group select {
        border-radius: 16px;
        border: 1px solid #eadbc9;
        background-color: #fffaf5;
        color: #2d1716;
        min-height: 48px;
        transition: all 0.2s ease;
    }

    .hosting-form-group input:focus,
    .hosting-form-group textarea:focus,
    .hosting-form-group select:focus {
        border-color: #a7601b;
        background-color: #ffffff;
        box-shadow: 0 0 0 0.22rem rgba(167, 96, 27, 0.13);
    }

    .hosting-help-text {
        display: block;
        color: #7a655d;
        font-size: 0.85rem;
        line-height: 1.55;
        margin-top: 0.42rem;
    }

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

    .hosting-submit-btn {
        background: linear-gradient(135deg, #321816, #a7601b);
        color: #ffffff;
        border: none;
        border-radius: 999px;
        font-weight: 850;
        min-height: 50px;
        padding: 0.82rem 1.4rem;
        box-shadow: 0 14px 28px rgba(167, 96, 27, 0.20);
    }

    .hosting-submit-btn:hover {
        color: #2d1716;
        background: linear-gradient(135deg, #ffc107, #ffe082);
        transform: translateY(-2px);
    }

    .hosting-gallery-grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 1.25rem;
    }

    .hosting-gallery-item-card {
        border-radius: 26px;
        overflow: hidden;
        background: #ffffff;
        border: 1px solid #efe2d3;
        box-shadow: 0 16px 34px rgba(58, 30, 24, 0.07);
        transition: 0.25s ease;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .hosting-gallery-item-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 24px 48px rgba(58, 30, 24, 0.12);
    }

    .hosting-gallery-image-wrap {
        position: relative;
        height: 220px;
        background: #fff4e4;
        overflow: hidden;
    }

    .hosting-gallery-image-wrap img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        transition: 0.35s ease;
    }

    .hosting-gallery-item-card:hover .hosting-gallery-image-wrap img {
        transform: scale(1.04);
    }

    .hosting-gallery-order-badge {
        position: absolute;
        left: 1rem;
        top: 1rem;
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.4rem 0.7rem;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.92);
        color: #2d1716;
        font-size: 0.72rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        backdrop-filter: blur(10px);
    }

    .hosting-gallery-item-body {
        padding: 1.15rem;
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .hosting-gallery-caption {
        color: #2d1716;
        font-weight: 850;
        line-height: 1.55;
        margin-bottom: 0.65rem;
    }

    .hosting-gallery-meta {
        color: #7a655d;
        font-size: 0.86rem;
        line-height: 1.55;
        margin-bottom: 1rem;
    }

    .hosting-gallery-actions {
        margin-top: auto;
        border-top: 1px solid #f0e4d6;
        padding-top: 0.95rem;
    }

    .hosting-gallery-actions .btn {
        border-radius: 999px;
        font-weight: 850;
        min-height: 42px;
    }

    .hosting-empty-gallery {
        text-align: center;
        padding: 3.5rem 1.5rem;
        border-radius: 28px;
        border: 1px dashed #d8bfa3;
        background: #fffaf5;
    }

    .hosting-empty-gallery-icon {
        width: 88px;
        height: 88px;
        border-radius: 30px;
        background: linear-gradient(135deg, #fff4e4, #ffe7aa);
        color: #a7601b;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 2.5rem;
        margin-bottom: 1.25rem;
        box-shadow: 0 18px 36px rgba(167, 96, 27, 0.14);
    }

    .hosting-empty-gallery h3 {
        color: #2d1716;
        font-weight: 950;
        margin-bottom: 0.55rem;
    }

    .hosting-empty-gallery p {
        color: #7a655d;
        max-width: 580px;
        margin: 0 auto;
        line-height: 1.75;
    }

    .hosting-side-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.09);
        overflow: hidden;
        position: sticky;
        top: 1rem;
        margin-bottom: 1.5rem;
    }

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

    .hosting-side-card-header h3 {
        color: #2d1716;
        font-weight: 950;
        margin-bottom: 0.25rem;
    }

    .hosting-side-card-header p {
        color: #7a655d;
        line-height: 1.65;
        margin-bottom: 0;
    }

    .hosting-side-card-body {
        padding: 1.45rem;
    }

    .hosting-tip-list {
        display: grid;
        gap: 0.95rem;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .hosting-tip-list li {
        display: flex;
        align-items: flex-start;
        gap: 0.7rem;
        color: #6f5b53;
        line-height: 1.65;
    }

    .hosting-tip-list i {
        color: #a7601b;
        font-size: 1.05rem;
        margin-top: 0.2rem;
        flex-shrink: 0;
    }

    .hosting-note-box {
        border-radius: 24px;
        padding: 1rem 1.1rem;
        background: #fff4e4;
        border: 1px solid #efd7ae;
        color: #7a4c18;
        line-height: 1.7;
        margin-top: 1.2rem;
    }

    .hosting-note-box strong {
        color: #2d1716;
    }

    .hosting-venue-mini-card {
        border-radius: 24px;
        overflow: hidden;
        background: #fffaf5;
        border: 1px solid #efe2d3;
        margin-bottom: 1rem;
    }

    .hosting-venue-mini-card img {
        width: 100%;
        height: 170px;
        object-fit: cover;
        display: block;
    }

    .hosting-venue-mini-placeholder {
        height: 170px;
        display: flex;
        align-items: center;
        justify-content: center;
        background:
            radial-gradient(circle at top right, rgba(255, 193, 7, 0.18), transparent 34%),
            linear-gradient(135deg, #fffaf5, #fff4e4);
        color: #a7601b;
        font-size: 2.5rem;
    }

    .hosting-venue-mini-body {
        padding: 1rem;
    }

    .hosting-venue-mini-body h4 {
        color: #2d1716;
        font-weight: 950;
        font-size: 1.05rem;
        margin-bottom: 0.35rem;
    }

    .hosting-venue-mini-body p {
        color: #7a655d;
        font-size: 0.9rem;
        line-height: 1.6;
        margin-bottom: 0;
    }

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

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

        .hosting-gallery-hero {
            padding: 2rem 1.45rem;
            border-radius: 30px;
        }

        .hosting-side-card {
            position: static;
        }
    }

    @media (max-width: 767.98px) {
        .hosting-gallery-hero-actions {
            flex-direction: column;
            align-items: stretch;
        }

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

        .hosting-gallery-grid {
            grid-template-columns: 1fr;
        }

        .hosting-gallery-card-body,
        .hosting-gallery-card-header,
        .hosting-side-card-header,
        .hosting-side-card-body {
            padding-left: 1.15rem;
            padding-right: 1.15rem;
        }
    }
</style>


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

        <!-- HERO -->
        <div class="hosting-gallery-hero">
            <div class="hosting-gallery-hero-inner">

                <span class="hosting-gallery-kicker">
                    <i class="bi bi-images"></i>
                    Venue Gallery
                </span>

                <h1>Manage Gallery Images</h1>

                <p>
                    Upload attractive venue images for <strong>{{ venue.venue_name }}</strong>.
                    Gallery images help Ensolanka review your venue and help guests understand the
                    atmosphere, setup, and experience your place can offer.
                </p>

                <div class="hosting-gallery-hero-actions">
                    <a href="{% url 'hosting_app:host_venue_detail' venue.slug %}"
                       class="btn hosting-btn-gold">
                        <i class="bi bi-eye-fill me-2"></i>
                        View Venue
                    </a>

                    <a href="{% url 'hosting_app:host_venue_update' venue.slug %}"
                       class="btn hosting-btn-light-outline">
                        <i class="bi bi-pencil-square me-2"></i>
                        Edit Venue
                    </a>

                    <a href="{% url 'hosting_app:host_venue_list' %}"
                       class="btn hosting-btn-light-outline">
                        <i class="bi bi-arrow-left-circle me-2"></i>
                        Back to Venues
                    </a>
                </div>

            </div>
        </div>


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

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

                <!-- UPLOAD FORM -->
                <div class="hosting-gallery-card">
                    <div class="hosting-gallery-card-header">
                        <h2>Add Gallery Image</h2>
                        <p>
                            Upload one image at a time. Use display order to control how images appear in the gallery.
                        </p>
                    </div>

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

                        <form method="post" enctype="multipart/form-data">
                            {% 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="row g-3">

                                <div class="col-md-12">
                                    <div class="hosting-form-group">
                                        <label for="{{ form.image.id_for_label }}">
                                            Gallery Image
                                        </label>

                                        {{ form.image }}

                                        {% if form.image.help_text %}
                                            <small class="hosting-help-text">
                                                {{ form.image.help_text }}
                                            </small>
                                        {% else %}
                                            <small class="hosting-help-text">
                                                Recommended: clear, bright images of seating areas, views, decorations,
                                                private areas, dining spaces, garden/beach/rooftop spaces, and event setup possibilities.
                                            </small>
                                        {% endif %}

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

                                <div class="col-md-8">
                                    <div class="hosting-form-group">
                                        <label for="{{ form.caption.id_for_label }}">
                                            Caption
                                        </label>

                                        {{ form.caption }}

                                        <small class="hosting-help-text">
                                            Optional. Example: “Private candlelight dinner area” or “Beachfront sunset setup”.
                                        </small>

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

                                <div class="col-md-4">
                                    <div class="hosting-form-group">
                                        <label for="{{ form.display_order.id_for_label }}">
                                            Display Order
                                        </label>

                                        {{ form.display_order }}

                                        <small class="hosting-help-text">
                                            Lower numbers appear first.
                                        </small>

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

                            </div>

                            <div class="d-flex flex-wrap gap-2 mt-3">
                                <button type="submit" class="btn hosting-submit-btn">
                                    <i class="bi bi-cloud-arrow-up-fill me-2"></i>
                                    Upload Image
                                </button>

                                <a href="{% url 'hosting_app:host_venue_detail' venue.slug %}"
                                   class="btn btn-outline-secondary rounded-pill fw-bold px-4">
                                    Cancel
                                </a>
                            </div>
                        </form>

                    </div>
                </div>


                <!-- GALLERY LIST -->
                <div class="hosting-gallery-card">
                    <div class="hosting-gallery-card-header">
                        <h3>Current Gallery Images</h3>
                        <p>
                            Review uploaded images and remove any image that is not suitable for this venue.
                        </p>
                    </div>

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

                        {% if gallery_images %}
                            <div class="hosting-gallery-grid">

                                {% for image in gallery_images %}
                                    <div class="hosting-gallery-item-card">

                                        <div class="hosting-gallery-image-wrap">
                                            <img src="{{ image.image.url }}"
                                                 alt="{{ image.caption|default:venue.venue_name }}">

                                            <span class="hosting-gallery-order-badge">
                                                <i class="bi bi-sort-numeric-down"></i>
                                                Order {{ image.display_order }}
                                            </span>
                                        </div>

                                        <div class="hosting-gallery-item-body">

                                            <div class="hosting-gallery-caption">
                                                {% if image.caption %}
                                                    {{ image.caption }}
                                                {% else %}
                                                    Venue gallery image
                                                {% endif %}
                                            </div>

                                            <div class="hosting-gallery-meta">
                                                Uploaded on {{ image.created_at|date:"M d, Y" }}
                                            </div>

                                            <div class="hosting-gallery-actions">
                                                <a href="{% url 'hosting_app:host_venue_gallery_delete' image.pk %}"
                                                   class="btn btn-outline-danger w-100">
                                                    <i class="bi bi-trash3-fill me-2"></i>
                                                    Delete Image
                                                </a>
                                            </div>

                                        </div>

                                    </div>
                                {% endfor %}

                            </div>
                        {% else %}

                            <div class="hosting-empty-gallery">
                                <div class="hosting-empty-gallery-icon">
                                    <i class="bi bi-images"></i>
                                </div>

                                <h3>No Gallery Images Yet</h3>

                                <p>
                                    Start by uploading attractive photos of your venue. Good gallery images can show
                                    the dining area, outdoor view, private space, romantic setup possibilities,
                                    lighting, garden, rooftop, beach, or celebration-ready areas.
                                </p>
                            </div>

                        {% endif %}

                    </div>
                </div>

            </div>


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

                <!-- VENUE PREVIEW -->
                <div class="hosting-side-card">
                    <div class="hosting-side-card-header">
                        <h3>Venue Preview</h3>
                        <p>
                            Basic details for the venue connected to this gallery.
                        </p>
                    </div>

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

                        <div class="hosting-venue-mini-card">

                            {% if venue.cover_image %}
                                <img src="{{ venue.cover_image.url }}"
                                     alt="{{ venue.venue_name }}">
                            {% else %}
                                <div class="hosting-venue-mini-placeholder">
                                    <i class="bi bi-building-heart"></i>
                                </div>
                            {% endif %}

                            <div class="hosting-venue-mini-body">
                                <h4>{{ venue.venue_name }}</h4>

                                <p>
                                    {% if venue.venue_category %}
                                        {{ venue.get_venue_category_display }}
                                    {% else %}
                                        Host Venue
                                    {% endif %}
                                    {% if venue.city or venue.district %}
                                        <br>
                                        <i class="bi bi-geo-alt-fill me-1"></i>
                                        {{ venue.city }}{% if venue.city and venue.district %}, {% endif %}{{ venue.district }}
                                    {% endif %}
                                </p>
                            </div>

                        </div>

                        <div class="hosting-note-box">
                            <strong>Gallery count:</strong>
                            {{ gallery_images.count }} image{{ gallery_images.count|pluralize }} uploaded.
                        </div>

                    </div>
                </div>


                <!-- IMAGE TIPS -->
                <div class="hosting-side-card">
                    <div class="hosting-side-card-header">
                        <h3>Image Tips</h3>
                        <p>
                            Better photos can improve guest interest and Ensolanka review quality.
                        </p>
                    </div>

                    <div class="hosting-side-card-body">
                        <ul class="hosting-tip-list">
                            <li>
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Use bright, clear, real images of your venue.</span>
                            </li>

                            <li>
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Show the areas suitable for romantic dates, proposals, dinners, and celebrations.</span>
                            </li>

                            <li>
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Include both wide venue photos and close-up atmosphere details.</span>
                            </li>

                            <li>
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Avoid blurry, dark, low-quality, or misleading photos.</span>
                            </li>

                            <li>
                                <i class="bi bi-check-circle-fill"></i>
                                <span>Use display order to place your strongest images first.</span>
                            </li>
                        </ul>

                        <div class="hosting-note-box">
                            <strong>Note:</strong>
                            Ensolanka may review, moderate, or remove images that are unclear, misleading,
                            inappropriate, or not suitable for public listing.
                        </div>
                    </div>
                </div>


                <!-- NEXT STEPS -->
                <div class="hosting-side-card">
                    <div class="hosting-side-card-header">
                        <h3>Next Steps</h3>
                        <p>
                            After adding gallery images, continue preparing your hosting services.
                        </p>
                    </div>

                    <div class="hosting-side-card-body">
                        <div class="d-grid gap-2">

                            <a href="{% url 'hosting_app:host_venue_detail' venue.slug %}"
                               class="btn btn-dark rounded-pill fw-bold">
                                <i class="bi bi-eye-fill me-2"></i>
                                View Venue Detail
                            </a>

                            <a href="{% url 'hosting_app:host_venue_update' venue.slug %}"
                               class="btn btn-outline-dark rounded-pill fw-bold">
                                <i class="bi bi-pencil-square me-2"></i>
                                Edit Venue Details
                            </a>

                            <a href="#"
                               class="btn btn-outline-secondary rounded-pill fw-bold">
                                <i class="bi bi-gift-fill me-2"></i>
                                Create Event Package
                            </a>

                            <a href="#"
                               class="btn btn-outline-secondary rounded-pill fw-bold">
                                <i class="bi bi-cup-hot-fill me-2"></i>
                                Add Meal Plan
                            </a>

                            <a href="#"
                               class="btn btn-outline-secondary rounded-pill fw-bold">
                                <i class="bi bi-stars me-2"></i>
                                Add Add-on Service
                            </a>

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

            </div>

        </div>

    </div>
</section>

{% endblock %}