{% extends 'rental_app/base_rental.html' %}
{% load static %}
{% load expat_extras %}

{% block title %}Rental Property Partner Information Center | Ensolanka{% endblock %}

{% block content %}

<style>
    /* =========================================================
       RENTAL PROPERTY PARTNER INFORMATION CENTER — RENTAL STYLE
    ========================================================= */

    .rental-info-page {
        min-height: 100vh;
        background: #f8fbff;
        padding-bottom: 5rem;
    }

    .rental-info-hero {
        background:
            linear-gradient(
                90deg,
                rgba(8, 20, 32, 0.92) 0%,
                rgba(8, 20, 32, 0.84) 45%,
                rgba(13, 110, 253, 0.62) 100%
            ),
            url("{% static 'expat_life/images/rental_hero.webp' %}") center center / cover no-repeat;
        color: #fff;
        padding: 5rem 0 4rem;
        position: relative;
        overflow: hidden;
    }

    .rental-info-hero::after {
        content: "";
        position: absolute;
        right: -90px;
        top: -90px;
        width: 280px;
        height: 280px;
        border-radius: 50%;
        background: rgba(255, 193, 7, 0.15);
        pointer-events: none;
    }

    .rental-info-hero .container {
        position: relative;
        z-index: 2;
    }

    .rental-info-hero .section-mini-title {
        color: #ffc107;
        font-size: .78rem;
        font-weight: 900;
        text-transform: uppercase;
        letter-spacing: .1em;
    }

    .rental-info-hero h1 {
        font-weight: 900;
        letter-spacing: -0.04em;
        line-height: 1.08;
    }

    .rental-info-hero p {
        color: rgba(255, 255, 255, 0.82);
        line-height: 1.8;
        max-width: 850px;
    }

    .rental-info-hero-card {
        background: rgba(255, 255, 255, 0.14);
        border: 1px solid rgba(255, 255, 255, 0.22);
        backdrop-filter: blur(14px);
        border-radius: 28px;
        padding: 2rem;
        box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
    }

    .rental-info-hero-card span {
        font-size: 0.78rem;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: rgba(255, 255, 255, 0.72);
        font-weight: 800;
    }

    .rental-info-hero-card h3 {
        color: #ffc107;
        font-weight: 900;
        margin-top: 0.55rem;
        margin-bottom: 0.7rem;
    }

    .rental-info-hero-card p {
        font-size: 0.94rem;
        margin-bottom: 0;
    }

    .rental-info-wrapper {
        margin-top: -2.2rem;
        position: relative;
        z-index: 5;
    }

    .rental-back-row {
        margin-bottom: 1rem;
    }

    .rental-back-row .btn {
        border-radius: 999px;
        font-weight: 800;
        box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
    }

    .rental-guidance-card {
        border-radius: 24px;
        overflow: hidden;
        background: #ffffff;
        border: none;
        box-shadow: 0 16px 45px rgba(13, 110, 253, 0.12);
    }

    .rental-guidance-header {
        background:
            linear-gradient(135deg, rgba(13, 27, 42, 0.98), rgba(13, 110, 253, 0.92));
        color: #fff;
        padding: 1.5rem 1.75rem;
        border-bottom: none;
    }

    .rental-guidance-header .section-mini-title {
        color: #ffc107;
        font-size: .76rem;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: .1em;
    }

    .rental-guidance-header h3 {
        font-weight: 850;
    }

    .rental-guidance-header p {
        color: rgba(255, 255, 255, .82);
        max-width: 820px;
    }

    .rental-info-note {
        border-radius: 20px;
        background: #eaf3ff;
        border: 1px solid #cfe2ff;
        color: #084298;
        padding: 1rem 1.1rem;
        line-height: 1.65;
        margin-bottom: 1.3rem;
    }

    .rental-info-note strong {
        color: #0d1b2a;
    }

    .rental-language-panel {
        display: none;
    }

    .rental-language-panel.active {
        display: block;
    }

    .rental-language-image-buttons {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: .65rem;
    }

    .rental-language-image-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        border-radius: 999px;
        opacity: 0.72;
        transition: all .22s ease;
        border: 2px solid transparent;
    }

    .rental-language-image-btn img {
        width: 150px;
        max-width: 100%;
        height: auto;
        display: block;
    }

    .rental-language-image-btn:hover {
        opacity: 1;
        transform: translateY(-2px);
        filter: drop-shadow(0 10px 18px rgba(13, 110, 253, 0.20));
    }

    .rental-language-image-btn.active {
        opacity: 1;
        transform: translateY(-2px);
        filter: drop-shadow(0 12px 22px rgba(13, 110, 253, 0.28));
    }

    .rental-guide-box,
    .rental-media-box {
        background: #f8fbff;
        border: 1px solid #dbeafe;
        border-radius: 20px;
        padding: 1.35rem;
    }

    .rental-guide-icon {
        width: 52px;
        height: 52px;
        border-radius: 18px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: #0d1b2a;
        color: #ffc107;
        font-size: 1.45rem;
        flex-shrink: 0;
    }

    .rental-guidance-list {
        list-style: none;
        padding: 0;
        margin: 0;
    }

    .rental-guidance-list li {
        display: flex;
        gap: .65rem;
        margin-bottom: .75rem;
        color: #475569;
        line-height: 1.58;
    }

    .rental-guidance-list li i {
        color: #16a34a;
        margin-top: .18rem;
        flex-shrink: 0;
    }

    .rental-video-wrapper {
        position: relative;
        width: 100%;
        padding-top: 56.25%;
        border-radius: 16px;
        overflow: hidden;
        background: #0d1b2a;
    }

    .rental-video-wrapper iframe {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        border: 0;
    }

    .rental-media-box audio {
        height: 40px;
    }

    .rental-empty-box {
        text-align: center;
        padding: 3rem 1.5rem;
        background: #f8fbff;
        border: 1px solid #dbeafe;
        border-radius: 22px;
    }

    .rental-empty-box i {
        font-size: 2.2rem;
        color: #0d6efd;
    }

    .rental-empty-box h5 {
        color: #0d1b2a;
        font-weight: 850;
        margin-top: 1rem;
    }

    .rental-empty-box p {
        color: #475569;
        max-width: 620px;
        margin-left: auto;
        margin-right: auto;
    }

    .rental-btn-primary {
        background: linear-gradient(135deg, #0d1b2a, #0d6efd);
        border: none;
        color: #fff;
    }

    .rental-btn-primary:hover {
        color: #fff;
        background: linear-gradient(135deg, #0d6efd, #0d1b2a);
    }

    @media (max-width: 991.98px) {
        .rental-info-hero {
            padding: 4rem 0 3.25rem;
        }

        .rental-info-hero-card {
            padding: 1.4rem;
        }

        .rental-language-image-buttons {
            justify-content: flex-start;
        }

        .rental-language-image-btn img {
            width: 135px;
        }
    }

    @media (max-width: 767.98px) {
        .rental-info-hero {
            text-align: center;
        }

        .rental-info-wrapper {
            margin-top: -1.5rem;
        }

        .rental-guidance-header,
        .card-body.p-4 {
            padding-left: 1.1rem !important;
            padding-right: 1.1rem !important;
        }

        .rental-language-image-buttons {
            justify-content: center;
        }

        .rental-language-image-btn img {
            width: 120px;
        }
    }

    @media (max-width: 420px) {
        .rental-language-image-btn img {
            width: 100px;
        }
    }
</style>


<section class="rental-info-page">

    <!-- HERO -->
    <div class="rental-info-hero">
        <div class="container">
            <div class="row align-items-center g-4">
                <div class="col-lg-8">
                    <span class="section-mini-title d-block mb-2">
                        Rental Property Partner Guidance Resources
                    </span>

                    <h1 class="display-4 mb-3">
                        Multilingual Information Center
                    </h1>

                    <p class="lead mb-0">
                        Access the Ensolanka Rental Property Partner Guidance Playbook,
                        summary overview, audio guide, and video guidance in English,
                        Sinhala, or Tamil.
                    </p>
                </div>

                <div class="col-lg-4">
                    <div class="rental-info-hero-card">
                        <span>Current Resource Center</span>
                        <h3>Property Partner Guidance</h3>
                        <p>
                            Learn how to list your property, understand the guided rental process,
                            prepare for international guests, and work with Ensolanka professionally.
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- CONTENT -->
    <div class="container rental-info-wrapper">

        <div class="rental-back-row d-flex flex-wrap gap-2 justify-content-between align-items-center">
            <a href="{% url 'rental_app:home_rental' %}"
               class="btn btn-light">
                <i class="bi bi-arrow-left-circle me-1"></i>
                Back to Rental Home
            </a>

            {% if request.user.is_authenticated %}
                <a href="{% url 'rental_app:rental_owner_dashboard' %}"
                   class="btn rental-btn-primary">
                    <i class="bi bi-speedometer2 me-1"></i>
                    Property Partner Dashboard
                </a>
            {% endif %}
        </div>


        <!-- Section: Rental Property Partner Guidance -->
        <div id="rental-guidance" class="card border-0 shadow-sm rental-guidance-card">
            <div class="card-header rental-guidance-header">
                <div>
                    <span class="section-mini-title d-block mb-1">
                        Property Partner Guidance
                    </span>

                    <h3 class="mb-1">
                        Playbook, Rental Guidance &amp; Property Partner Support
                    </h3>

                    <p class="mb-0">
                        Understand how to present your property, prepare for international guests,
                        handle expectations clearly, and follow the guided rental partner process.
                    </p>
                </div>
            </div>

            <div class="card-body p-4">

                {% if guidance_resources %}

                    <div class="rental-info-note">
                        <strong>Select a language below.</strong>
                        The guidance playbook, downloadable documents, audio guide, and video guidance
                        will change according to your selected language.
                    </div>

                    <!-- Language Image Buttons -->
                    <div class="rental-language-image-buttons mb-3">

                        <a href="?lang=si"
                           class="rental-language-image-btn {% if selected_language == 'si' %}active{% endif %}"
                           data-guidance-lang="si"
                           aria-label="Open Sinhala resources">
                            <img src="{% static 'expat_life/images/sinhala.png' %}"
                                 alt="Sinhala">
                        </a>

                        <a href="?lang=ta"
                           class="rental-language-image-btn {% if selected_language == 'ta' %}active{% endif %}"
                           data-guidance-lang="ta"
                           aria-label="Open Tamil resources">
                            <img src="{% static 'expat_life/images/tamil.png' %}"
                                 alt="Tamil">
                        </a>

                        <a href="?lang=en"
                           class="rental-language-image-btn {% if selected_language == 'en' %}active{% endif %}"
                           data-guidance-lang="en"
                           aria-label="Open English resources">
                            <img src="{% static 'expat_life/images/english.png' %}"
                                 alt="English">
                        </a>

                    </div>


                    <!-- Guidance Content Panels -->
                    {% for resource in guidance_resources %}
                        <div class="rental-language-panel {% if resource.language == selected_language %}active{% endif %}"
                             data-guidance-panel="{{ resource.language }}">

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

                                <!-- Left: Guidance Details -->
                                <div class="col-lg-7">
                                    <div class="rental-guide-box h-100">

                                        <div class="d-flex align-items-start gap-3 mb-3">
                                            <div class="rental-guide-icon">
                                                <i class="bi bi-house-heart-fill"></i>
                                            </div>

                                            <div>
                                                <span class="badge rounded-pill bg-warning text-dark mb-2">
                                                    {{ resource.get_language_display }}
                                                </span>

                                                <h4 class="fw-bold mb-1">
                                                    {{ resource.title }}
                                                </h4>

                                                {% if resource.description %}
                                                    <p class="text-muted mb-0">
                                                        {{ resource.description|linebreaksbr }}
                                                    </p>
                                                {% else %}
                                                    <p class="text-muted mb-0">
                                                        Complete guidance materials to help rental property partners
                                                        understand listing, preparation, guest expectations, and the
                                                        guided rental process.
                                                    </p>
                                                {% endif %}
                                            </div>
                                        </div>

                                        <div class="playbook-summary mt-4">
                                            <h5 class="fw-bold mb-3">
                                                Guidance Materials
                                            </h5>

                                            <ul class="rental-guidance-list">
                                                <li>
                                                    <i class="bi bi-check-circle-fill"></i>
                                                    Read the complete rental property partner guidance playbook for this language.
                                                </li>
                                                <li>
                                                    <i class="bi bi-check-circle-fill"></i>
                                                    Download the summary overview for quick reference.
                                                </li>
                                                <li>
                                                    <i class="bi bi-check-circle-fill"></i>
                                                    Listen to the audio guide to understand the rental partner process clearly.
                                                </li>
                                                <li>
                                                    <i class="bi bi-check-circle-fill"></i>
                                                    Watch the video guidance before listing or managing your property.
                                                </li>
                                            </ul>
                                        </div>

                                        <div class="d-flex flex-column flex-md-row flex-wrap gap-2 mt-4">

                                            {% if resource.full_playbook_pdf %}
                                                <a href="{{ resource.full_playbook_pdf.url }}"
                                                   class="btn rental-btn-primary rounded-pill px-4"
                                                   target="_blank">
                                                    <i class="bi bi-file-earmark-pdf me-1"></i>
                                                    View Full Playbook
                                                </a>

                                                <a href="{{ resource.full_playbook_pdf.url }}"
                                                   class="btn btn-outline-dark rounded-pill px-4"
                                                   download>
                                                    <i class="bi bi-download me-1"></i>
                                                    Download Full Playbook
                                                </a>
                                            {% endif %}

                                            {% if resource.summary_overview_pdf %}
                                                <a href="{{ resource.summary_overview_pdf.url }}"
                                                   class="btn btn-outline-primary rounded-pill px-4"
                                                   download>
                                                    <i class="bi bi-file-earmark-text me-1"></i>
                                                    Download Summary Overview
                                                </a>
                                            {% endif %}

                                        </div>

                                        {% if not resource.full_playbook_pdf and not resource.summary_overview_pdf %}
                                            <p class="text-muted small mt-4 mb-0">
                                                Document files for this language will be available soon.
                                            </p>
                                        {% endif %}

                                    </div>
                                </div>


                                <!-- Right: Audio + Video -->
                                <div class="col-lg-5">

                                    <!-- Audio Guidance -->
                                    <div class="rental-media-box mb-4">
                                        <h5 class="fw-bold mb-2">
                                            <i class="bi bi-headphones me-1"></i>
                                            Audio Guidance
                                        </h5>

                                        {% if resource.audio_guide_file %}
                                            <audio controls preload="metadata" class="w-100 mb-3">
                                                <source src="{{ resource.audio_guide_file.url }}" type="audio/mpeg">
                                                Your browser does not support the audio element.
                                            </audio>

                                            <a href="{{ resource.audio_guide_file.url }}"
                                               class="btn btn-outline-secondary btn-sm rounded-pill"
                                               download>
                                                <i class="bi bi-download me-1"></i>
                                                Download Audio File
                                            </a>
                                        {% else %}
                                            <p class="text-muted small mb-0">
                                                Audio guidance for this language will be available soon.
                                            </p>
                                        {% endif %}
                                    </div>


                                    <!-- Video Guidance -->
                                    <div class="rental-media-box">
                                        <h5 class="fw-bold mb-2">
                                            <i class="bi bi-play-circle-fill me-1"></i>
                                            Video Guidance
                                        </h5>

                                        {% if resource.youtube_video_link %}
                                            {% with resource.youtube_video_link|video_embed_url as embed_url %}
                                                {% if embed_url %}
                                                    <div class="rental-video-wrapper">
                                                        <iframe
                                                            src="{{ embed_url }}"
                                                            title="{{ resource.title }} Video Guidance"
                                                            allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
                                                            referrerpolicy="strict-origin-when-cross-origin"
                                                            allowfullscreen
                                                            loading="lazy">
                                                        </iframe>
                                                    </div>
                                                {% else %}
                                                    <p class="text-muted small mb-0">
                                                        Video link is available, but it could not be embedded.
                                                    </p>
                                                {% endif %}
                                            {% endwith %}
                                        {% else %}
                                            <p class="text-muted small mb-0">
                                                Video guidance for this language will be available soon.
                                            </p>
                                        {% endif %}
                                    </div>

                                </div>

                            </div>

                        </div>
                    {% endfor %}

                {% else %}

                    <div class="rental-empty-box">
                        <i class="bi bi-journal-x"></i>

                        <h5>
                            Guidance resources are not available yet
                        </h5>

                        <p class="mb-0">
                            The Ensolanka Rental Property Partner Guidance Playbook, summary, audio guide,
                            and video guidance will appear here once published.
                        </p>
                    </div>

                {% endif %}

            </div>
        </div>

    </div>
</section>


<script>
    document.addEventListener('DOMContentLoaded', function () {
        const buttons = document.querySelectorAll('[data-guidance-lang]');
        const panels = document.querySelectorAll('.rental-language-panel');

        function activateLanguage(selectedLang, updateUrl = true) {
            buttons.forEach(function (btn) {
                if (btn.getAttribute('data-guidance-lang') === selectedLang) {
                    btn.classList.add('active');
                } else {
                    btn.classList.remove('active');
                }
            });

            panels.forEach(function (panel) {
                if (panel.getAttribute('data-guidance-panel') === selectedLang) {
                    panel.classList.add('active');
                } else {
                    panel.classList.remove('active');
                }
            });

            if (updateUrl) {
                const newUrl = new URL(window.location.href);
                newUrl.searchParams.set('lang', selectedLang);
                window.history.pushState({}, '', newUrl);
            }
        }

        buttons.forEach(function (button) {
            button.addEventListener('click', function (event) {
                event.preventDefault();

                const selectedLang = this.getAttribute('data-guidance-lang');
                activateLanguage(selectedLang, true);
            });
        });

        const urlParams = new URLSearchParams(window.location.search);
        const initialLang = urlParams.get('lang') || '{{ selected_language|default:"en" }}';

        if (initialLang) {
            activateLanguage(initialLang, false);
        }
    });
</script>

{% endblock %}