PK

ADDRLIN : C:/Inetpub/vhosts/dharmayatra.co.in/httpdocs/
FLL :
Current File : C:/Inetpub/vhosts/dharmayatra.co.in/httpdocs/package_details.php

<?php
include './includes/db.php';

session_start();

$booking_success = false;
$whatsapp_link = '';

if (isset($_GET['success']) && isset($_SESSION['whatsapp_link'])) {
    $booking_success = true;
    $whatsapp_link = $_SESSION['whatsapp_link'];

    // 🔥 VERY IMPORTANT: clear session so it runs only once
    unset($_SESSION['whatsapp_link']);
}

$package_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$package = null;

if ($package_id) {
    $stmt = $conn->prepare("SELECT p.*, c.name as category_name FROM packages p JOIN categories c ON p.category_id = c.id WHERE p.id = ? AND p.status = 1");
    $stmt->bind_param("i", $package_id);
    $stmt->execute();
    $package = $stmt->get_result()->fetch_assoc();
}

if (!$package) {
    header('Location: index.php');
    exit();
}

// Fetch addons for this package
$addons = $conn->query("SELECT * FROM package_addons WHERE package_id = $package_id");


// Handle booking submission
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['book_package'])) {

    $customer_name = $_POST['customer_name'] ?? '';
    $start_date = $_POST['package_date'] ?? '';

    $selected_addons = $_POST['addons'] ?? [];

    $total_price = $package['price'];
    $addon_details = "";

    // ================= CALCULATE ADDONS =================
    if (!empty($selected_addons)) {
        $ids = implode(",", array_map('intval', $selected_addons));
        $addon_query = $conn->query("SELECT * FROM package_addons WHERE id IN ($ids)");

        while ($a = $addon_query->fetch_assoc()) {
            $total_price += $a['price'];
            $addon_details .= $a['name'] . " (₹" . number_format($a['price']) . "), ";
        }
    }

    // ================= SAVE BOOKING =================
    $stmt = $conn->prepare("
        INSERT INTO bookings 
        (package_id, package_title, start_date, customer_name, total_price) 
        VALUES (?, ?, ?, ?, ?)
    ");
    $stmt->bind_param("isssd", $package_id, $package['title'], $start_date, $customer_name, $total_price);

    if ($stmt->execute()) {

        $booking_id = $stmt->insert_id;

        // SAVE ADDONS
        if (!empty($selected_addons)) {
            foreach ($selected_addons as $addon_id) {

                $addon_id = intval($addon_id);

                $addonData = $conn->query("SELECT * FROM package_addons WHERE id = $addon_id")->fetch_assoc();

                if ($addonData) {
                    $stmtAddon = $conn->prepare("
                    INSERT INTO booking_addons 
                    (booking_id, addon_id, addon_name, price) 
                    VALUES (?, ?, ?, ?)
                ");
                    $stmtAddon->bind_param(
                        "iisd",
                        $booking_id,
                        $addon_id,
                        $addonData['name'],
                        $addonData['price']
                    );
                    $stmtAddon->execute();
                }
            }
        }

        // WhatsApp message
        $msg = "New Booking Request!\n\n";
        $msg .= "Package: " . $package['title'] . "\n";
        $msg .= "Name: $customer_name\n";
        $msg .= "Travel Date: $start_date\n";

        if ($addon_details) {
            $msg .= "Add-ons: " . rtrim($addon_details, ', ') . "\n";
        }

        $msg .= "Total Price: ₹ " . number_format($total_price);

        $whatsapp_number = "8328930086";
        $whatsapp_link = "https://wa.me/$whatsapp_number?text=" . urlencode($msg);

        // ✅ SET SUCCESS
        // $booking_success = true;
        $_SESSION['whatsapp_link'] = $whatsapp_link;

        // Redirect to same page (GET request)
        header("Location: package_details.php?id=$package_id&success=1");
        exit();
    } else {
        $booking_error = "Error processing booking.";
    }
}
?>

<?php include './includes/header.php' ?>





<?php if (isset($booking_success) && $booking_success): ?>
    <div class="alert alert-success alert-dismissible fade show m-3" role="alert">
        <strong>Booking Submitted Successfully!</strong> Redirecting to WhatsApp...
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
<?php endif; ?>

<?php if (isset($booking_error)): ?>
    <div class="alert alert-danger m-3"><?php echo $booking_error; ?></div>
<?php endif; ?>



<style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    body {
        font-family: 'Inter', sans-serif;
        background: #fefaf5;
        color: #2c2418;
        line-height: 1.5;
    }

    /* container max-width modern */
    .container {
        max-width: 1280px;
        margin: 0 auto;
        padding: 0 24px;
    }

    /* section spacing */
    section {
        margin-bottom: 3rem;
    }

    /* headings */
    h1,
    h2,
    h3 {
        font-family: 'Playfair Display', serif;
        font-weight: 700;
        letter-spacing: -0.01em;
    }

    h1 {
        font-size: 2.5rem;
        color: #b45f2b;
        margin-bottom: 0.5rem;
        position: relative;
        display: inline-block;
    }

    .has-orange-border {
        position: relative;
        display: inline-block;
        font-size: 1.9rem;
        margin-bottom: 1.5rem;
        padding-bottom: 0.5rem;
        color: #3e2a1f;
    }

    .has-orange-border:after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 70px;
        height: 4px;
        background: #e67e22;
        border-radius: 4px;
    }

    /* Gallery Redesign - glassmorphism + modern grid */
    .temple-gallary-section {
        padding: 2rem 0 1rem;
    }

    .temple-gallary-wrapper {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
        margin-top: 2rem;
    }

    .left-block.gallery .image-wrapper {
        border-radius: 28px;
        overflow: hidden;
        height: 100%;
        box-shadow: 0 20px 35px -12px rgba(0, 0, 0, 0.2);
        transition: transform 0.3s ease;
    }

    .left-block.gallery .image-wrapper:hover {
        transform: scale(1.01);
    }

    .left-block.gallery img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        min-height: 380px;
        display: block;
    }

    .right-block .right-inner {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
        height: 100%;
    }

    .right-block .image-wrapper {
        border-radius: 24px;
        overflow: hidden;
        box-shadow: 0 12px 28px -8px rgba(0, 0, 0, 0.12);
        background: #fff;
        transition: all 0.25s;
    }

    .image-inner {
        position: relative;
        height: 100%;
    }

    .image-inner img {
        width: 100%;
        height: 180px;
        object-fit: cover;
        display: block;
        transition: transform 0.4s;
    }

    .image-wrapper:hover img {
        transform: scale(1.03);
    }

    .has-more-image .image-inner {
        position: relative;
    }

    .modal-btn {
        position: absolute;
        bottom: 16px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(8px);
        color: white;
        padding: 8px 18px;
        border-radius: 40px;
        font-size: 0.85rem;
        font-weight: 600;
        text-decoration: none;
        font-family: 'Inter', sans-serif;
        transition: 0.2s;
        letter-spacing: 0.3px;
    }

    .modal-btn:hover {
        background: #e67e22;
        color: white;
    }

    .phone_inq {
        background: #fff1e6;
        display: inline-flex;
        align-items: center;
        gap: 10px;
        padding: 8px 22px;
        border-radius: 50px;
        text-decoration: none;
        color: #b45f2b;
        font-weight: 600;
        transition: 0.2s;
        border: 1px solid #ffd9b5;
    }

    .phone_inq i {
        font-size: 1.2rem;
    }

    .phone_inq:hover {
        background: #e67e22;
        color: white;
        border-color: #e67e22;
    }

    /* about card style */
    .about-section {
        background: white;
        border-radius: 32px;
        padding: 1.8rem 2rem;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.03);
        transition: box-shadow 0.2s;
        border: 1px solid #f5e6da;
    }

    .about-inner-wrapper {
        width: 100%;
    }

    .div_about {
        font-size: 1rem;
        color: #4a3b2c;
        line-height: 1.6;
        transition: all 0.3s;
    }

    .over_flow {
        overflow: hidden;
        height: 100px;
    }

    .read_more {
        display: inline-block;
        margin-top: 1rem;
        color: #e67e22;
        font-weight: 600;
        cursor: pointer;
        text-decoration: none;
        border-bottom: 1px dashed #e67e22;
    }

    .about-list {
        list-style: none;
        padding: 0;
        display: flex;
        flex-wrap: wrap;
        gap: 24px;
        margin-top: 10px;
    }

    .about-list li {
        background: #fef3e9;
        padding: 10px 20px;
        border-radius: 60px;
        font-weight: 500;
        display: inline-flex;
        align-items: center;
        gap: 12px;
    }

    .about-list li i {
        color: #e67e22;
        font-size: 1.2rem;
    }

    /* booking card modern */
    .puja-booking-section {
        background: linear-gradient(135deg, #fff6ed 0%, #ffffff 100%);
        border: 1px solid #ffdec2;
    }

    .package-price span {
        font-size: 1.8rem;
        font-weight: 800;
        color: #b45f2b;
        background: #fff0e4;
        display: inline-block;
        padding: 6px 24px;
        border-radius: 60px;
    }

    .form-wrapper {
        background: white;
        padding: 1.8rem;
        border-radius: 28px;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.05);
        margin: 20px 0 15px;
    }

    .form-group label {
        font-weight: 600;
        margin-bottom: 8px;
        color: #3e2a1f;
    }

    .form-control,
    select.form-control {
        border-radius: 60px;
        border: 1px solid #f0dbc9;
        padding: 12px 20px;
        background: #fefaf7;
        transition: 0.2s;
    }

    .form-control:focus {
        border-color: #e67e22;
        box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.2);
    }

    .book-button button {
        background: #e67e22;
        border: none;
        color: white;
        font-weight: 700;
        padding: 12px 28px;
        border-radius: 60px;
        width: 100%;
        transition: 0.2s;
        font-size: 1rem;
    }

    .book-button button:hover {
        background: #c95f0e;
        transform: translateY(-2px);
    }

    /* sticky floating button */
    #myBtn {
        display: none;
        position: fixed;
        bottom: 30px;
        z-index: 999;
        background: #e67e22;
        color: white;
        border: none;
        padding: 14px 32px;
        border-radius: 60px;
        font-weight: 700;
        font-size: 1rem;
        box-shadow: 0 8px 20px rgba(230, 126, 34, 0.4);
        cursor: pointer;
        transition: 0.2s;
        font-family: 'Inter', sans-serif;
        border: none;
        width: auto;
        white-space: nowrap;
    }

    #myBtn:hover {
        background: #c24f0a;
        transform: scale(1.02);
    }

    /* Accordion styling (keeps original functionality but fresh) */
    .accordion-outer {
        margin-top: 1rem;
    }

    .accordion-item {
        background: #fef9f4;
        border-radius: 20px;
        margin-bottom: 12px;
        border: 1px solid #f3e5d9;
        overflow: hidden;
    }

    .accordion-title {
        padding: 1rem 1.5rem;
        font-weight: 700;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: white;
    }

    .accordion-title img {
        transition: transform 0.3s;
        width: 20px;
    }

    .rotated {
        transform: rotate(180deg);
    }

    .accordion-content {
        padding: 0 1.5rem 1.2rem 1.5rem;
        display: none;
        border-top: 1px solid #f3e0cf;
        background: #fffcf9;
    }

    /* lists */
    .uili ul,
    .about-inner-wrapper ul {
        list-style: none;
        padding-left: 0;
    }

    .uili li,
    .about-inner-wrapper ul li {
        padding-left: 28px;
        position: relative;
        margin-bottom: 10px;
        font-weight: 500;
    }

    .uili li:before,
    .about-inner-wrapper ul li:before {
        content: "✓";
        color: #e67e22;
        font-weight: bold;
        position: absolute;
        left: 0;
    }

    /* modal wrapper (gallery popup) - minimal but functional */
    .modal-wrapper {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.85);
        z-index: 2000;
        justify-content: center;
        align-items: center;
        backdrop-filter: blur(5px);
    }

    .modal-content-gallery {
        max-width: 90%;
        max-height: 80%;
        background: #fff;
        border-radius: 32px;
        padding: 20px;
        position: relative;
        text-align: center;
    }

    .modal-content-gallery img {
        max-width: 100%;
        max-height: 70vh;
        border-radius: 20px;
    }

    .close-btn {
        position: absolute;
        top: 10px;
        right: 20px;
        font-size: 32px;
        cursor: pointer;
        color: #333;
    }

    /* .  {
            display: none;
        } */

    @media (max-width: 860px) {
        .temple-gallary-wrapper {
            grid-template-columns: 1fr;
            gap: 20px;
        }

        .right-block .right-inner {
            grid-template-columns: repeat(2, 1fr);
        }

        h1 {
            font-size: 1.9rem;
        }

        .about-section {
            padding: 1.2rem;
        }

        .container {
            padding: 0 18px;
        }

        .about-list li {
            font-size: 0.9rem;
        }

        #myBtn {
            padding: 10px 20px;
            font-size: 0.9rem;
            white-space: nowrap;
        }
    }

    @media (max-width: 560px) {
        .right-block .right-inner {
            grid-template-columns: 1fr;
        }

        .form-wrapper .row {
            flex-direction: column;
        }

        .col-lg-5,
        .col-lg-2 {
            width: 100%;
            margin-bottom: 12px;
        }
    }

    /* footer { display: none; } */


    /* add on packages  */
    .addon-box {
        border: 1px solid #eee;
        padding: 15px;
        border-radius: 12px;
        background: #fff7f0;
    }

    .addon-item {
        margin-bottom: 10px;
        padding: 10px;
        border-radius: 8px;
        background: #fff;
        border: 1px solid #f3d2b5;
    }

    .addon-item input {
        margin-right: 10px;
    }
</style>


<main>
    <div class="container">
        <!-- GALLERY SECTION (REDESIGN but full PHP untouched) -->
        <section class="temple-gallary-section">
            <div class="container">
                <div class="temple-gallary-inner">
                    <div style="text-align: center;">
                        <h1><?php echo $package['title']; ?></h1>
                        <div class="login_text" style="margin: 12px 0 20px;">
                            <a href="tel:8328930086" class="phone_inq"><i class="fas fa-phone-alt"></i> Call now for enquiry: <u>8328930086</u></a>
                        </div>
                    </div>
                    <div class="temple-gallary-wrapper">
                        <div class="left-block gallery">
                            <div class="image-wrapper">
                                <img src="<?php echo $package['main_image']; ?>" alt="<?php echo $package['title']; ?>">
                            </div>
                        </div>
                        <div class="right-block">
                            <div class="right-inner">
                                <?php
                                $images = explode(',', $package['images']);
                                foreach (array_slice($images, 0, 3) as $img):
                                ?>
                                    <div class="image-wrapper">
                                        <div class="image-inner">
                                            <img src="<?php echo trim($img); ?>" alt="Package Image">
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                                <div class="image-wrapper has-more-image">
                                    <div class="image-inner">
                                        <img src="<?php echo $package['main_image']; ?>" alt="More Images">
                                        <a href="#" class="modal-btn" data-link="gallary-popup">View More</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Package Overview (attractive card) -->
        <section class="about-section">
            <div class="container">
                <div class="about-inner-wrapper">
                    <h2 class="has-orange-border">Package Overview</h2>
                    <div class="div_about over_flow" style="overflow: hidden; height: 100px;">
                        <?php echo $package['full_description']; ?>
                    </div>
                    <a class="read_more" id="readMoreBtn">Read More</a>
                </div>
            </div>
        </section>

        <!-- Things Included -->
        <section class="about-section">
            <div class="container">
                <div class="about-inner-wrapper">
                    <h2 class="has-orange-border">Things Included</h2>
                    <ul class="about-list">
                        <li><i class="fas fa-clock"></i> Duration: <?php echo $package['duration']; ?></li>
                        <li><i class="fas fa-bed"></i> Stay: Yes</li>
                        <li><i class="fas fa-binoculars"></i> Sightseeing: Yes</li>
                        <li><i class="fas fa-taxi"></i> Transportation: Yes</li>
                        <li><i class="fas fa-utensils"></i> Meal: Yes</li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- BOOKING SECTION (preserved IDs and classes + sticky anchor) -->
        <section class="about-section puja-booking-section" id="package_book_section">
            <div class="container">
                <div class="about-inner-wrapper package-price">
                    <h2>Book <?php echo $package['title']; ?></h2>
                    <div class="form-wrapper">
                        <form method="POST" id="booking_form">
                            <input type="hidden" name="book_package" value="1">

                            <div class="row g-3">

                                <!-- Name -->
                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <label>Your Name</label>
                                        <input type="text" name="customer_name" class="form-control" required>
                                    </div>
                                </div>

                                <!-- Travel Date -->
                                <div class="col-lg-6">
                                    <div class="form-group">
                                        <label>Travel Date</label>
                                        <input type="date" name="package_date" class="form-control" required>
                                    </div>
                                </div>

                                <!-- ADDONS SECTION -->
                                <?php if ($addons && $addons->num_rows > 0): ?>
                                    <div class="col-12">
                                        <label style="font-weight:600;">Optional Add-ons</label>
                                    </div>

                                    <?php while ($addon = $addons->fetch_assoc()): ?>
                                        <div class="col-lg-6">
                                            <div class="addon-item">
                                                <label>
                                                    <input type="checkbox" class="addon-checkbox"
                                                        name="addons[]"
                                                        value="<?php echo $addon['id']; ?>"
                                                        data-price="<?php echo $addon['price']; ?>"
                                                        data-name="<?php echo htmlspecialchars($addon['name']); ?>">

                                                    <strong><?php echo $addon['name']; ?></strong>
                                                    <span>(₹ <?php echo number_format($addon['price']); ?>)</span>
                                                    <br>
                                                    <small><?php echo $addon['description']; ?></small>
                                                </label>
                                            </div>
                                        </div>
                                    <?php endwhile; ?>
                                <?php endif; ?>

                                <!-- TOTAL -->
                                <div class="col-12">
                                    <div class="form-group mt-3">
                                        <h4>Total Price: ₹ <span id="totalPrice"><?php echo number_format($package['price']); ?></span></h4>
                                    </div>
                                </div>

                                <!-- BUTTON -->
                                <div class="col-12">
                                    <button type="submit" id="book_now" class="btn btn-success w-100">
                                        Book Now
                                    </button>
                                </div>

                            </div>
                        </form>
                    </div>
                    <span style="display: block; text-align: center; margin-top: 12px; font-weight: 600;">Starting From - ₹ <?php echo number_format($package['price']); ?> Per Person</span>
                </div>
            </div>
        </section>

        <!-- Package Itinerary -->
        <section class="about-section">
            <div class="container">
                <div class="about-inner-wrapper">
                    <h2 class="has-orange-border">Package Itinerary</h2>
                    <div class="accordion-outer">
                        <?php echo $package['itinerary']; ?>
                    </div>
                </div>
            </div>
        </section>

        <!-- Package Inclusions -->
        <section class="about-section">
            <div class="container">
                <div class="about-inner-wrapper uili">
                    <h2 class="has-orange-border">Package Inclusions</h2>
                    <ul>
                        <?php
                        $inclusions = explode("\n", $package['inclusions']);
                        foreach ($inclusions as $item):
                            if (trim($item)):
                        ?>
                                <li><?php echo $item; ?></li>
                        <?php
                            endif;
                        endforeach;
                        ?>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Package Exclusions -->
        <section class="about-section">
            <div class="container">
                <div class="about-inner-wrapper">
                    <h2 class="has-orange-border">Package Exclusions</h2>
                    <ul>
                        <?php
                        $exclusions = explode("\n", $package['exclusions']);
                        foreach ($exclusions as $item):
                            if (trim($item)):
                        ?>
                                <li><?php echo $item; ?></li>
                        <?php
                            endif;
                        endforeach;
                        ?>
                    </ul>
                </div>
            </div>
        </section>
    </div>
</main>

<button id="myBtn">✨ Book Your Package</button>

<!-- Modal Gallery (hidden initially) -->
<div class="modal-wrapper" id="galleryModal" style="display: none;">
    <div class="modal-content-gallery">
        <span class="close-btn">&times;</span>
        <div style="text-align:center; margin-bottom: 10px;">
            <h4>Package Gallery</h4>
        </div>
        <div id="modalGalleryInner" style="display:flex; flex-wrap:wrap; justify-content:center; gap:12px;">
            <!-- will populate with all images -->
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // ---------- preserve original accordion logic ----------
    $('.accordion-title').click(function() {
        $(this).next('.accordion-content').slideToggle();
        $(this).find('img').toggleClass('rotated');
    });

    // ---------- Read More / Less (original logic with dynamic height) but we keep both implementations.
    // Actually we have two similar scripts but we unify for overview section only.
    $('#readMoreBtn').click(function() {
        var contentDiv = $('.div_about');
        if (contentDiv.hasClass('over_flow')) {
            contentDiv.removeClass('over_flow').css('height', 'auto');
            $(this).text('Read Less');
        } else {
            contentDiv.addClass('over_flow').css('height', '100px');
            $(this).text('Read More');
        }
    });
    // also the second script listener but we avoid duplication, keep same behavior.
    // fix any conflict: we merge.
    if (typeof window.originalReadMore === 'undefined') {
        window.addEventListener('load', function() {
            var btn = document.getElementById('readMoreBtn');
            if (btn) {
                // override to ensure parity
                var newBtn = btn.cloneNode(true);
                btn.parentNode.replaceChild(newBtn, btn);
                newBtn.addEventListener('click', function(e) {
                    var contentDiv = document.querySelector('.div_about');
                    if (contentDiv.classList.contains('over_flow')) {
                        contentDiv.classList.remove('over_flow');
                        contentDiv.style.height = 'auto';
                        newBtn.textContent = 'Read Less';
                    } else {
                        contentDiv.classList.add('over_flow');
                        contentDiv.style.height = '100px';
                        newBtn.textContent = 'Read More';
                    }
                });
            }
        });
    }

    // ---------- scroll to booking ----------
    function scrollToBooking() {
        document.getElementById('package_book_section').scrollIntoView({
            behavior: 'smooth'
        });
    }
    // sticky button logic (preserved and enhanced)
    window.addEventListener('scroll', function() {
        var mybutton = document.getElementById("myBtn");
        if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
            mybutton.style.display = "block";
            var leftPosition = (window.innerWidth - mybutton.offsetWidth) / 2;
            mybutton.style.left = leftPosition + "px";
        } else {
            mybutton.style.display = "none";
        }
    });
    window.addEventListener("resize", function() {
        var mybutton = document.getElementById("myBtn");
        if (mybutton.style.display === "block") {
            var leftPosition = (window.innerWidth - mybutton.offsetWidth) / 2;
            mybutton.style.left = leftPosition + "px";
        }
    });
    // button click action
    document.getElementById("myBtn")?.addEventListener("click", function() {
        scrollToBooking();
    });

    // ---------- modal gallery (view more) ----------
    $('.modal-btn').click(function(e) {
        e.preventDefault();
        // gather all images from package images + main_image maybe
        var mainImg = "<?php echo addslashes($package['main_image']); ?>";
        var imagesRaw = "<?php echo addslashes($package['images']); ?>";
        var allImages = [];
        if (mainImg) allImages.push(mainImg);
        var splitImgs = imagesRaw.split(',');
        for (var i = 0; i < splitImgs.length; i++) {
            var trimmed = splitImgs[i].trim();
            if (trimmed && !allImages.includes(trimmed)) allImages.push(trimmed);
        }
        var modalInner = $('#modalGalleryInner');
        modalInner.empty();
        allImages.forEach(function(imgSrc) {
            var imgDiv = $('<div style="width:150px; height:150px; border-radius:18px; overflow:hidden; box-shadow:0 6px 12px rgba(0,0,0,0.1);"><img src="' + imgSrc + '" style="width:100%; height:100%; object-fit:cover;"></div>');
            modalInner.append(imgDiv);
        });
        $('.modal-wrapper').fadeIn();
    });
    $('.close-btn').click(function() {
        $('.modal-wrapper').fadeOut();
    });
    $(window).click(function(e) {
        if ($(e.target).hasClass('modal-wrapper')) {
            $('.modal-wrapper').fadeOut();
        }
    });

    // review_more_btn functionality if present (dynamically)
    if (typeof document.querySelectorAll !== 'undefined') {
        document.querySelectorAll('.review_more_btn').forEach(function(button) {
            button.addEventListener('click', function() {
                var contentDiv = document.querySelector('#review_more_' + $(this).attr("data_val"));
                var height = "";
                if ($(window).width() >= 991) height = "25px";
                else if ($(window).width() < 991 && $(window).width() > 768) height = "25px";
                else height = "20px";
                if (contentDiv.style.height === height) {
                    contentDiv.style.height = 'auto';
                    $('#review_more_' + $(this).attr("data_val")).removeClass('over_flow');
                    this.textContent = 'Read Less';
                } else {
                    contentDiv.style.height = height;
                    $('#review_more_' + $(this).attr("data_val")).addClass('over_flow');
                    this.textContent = 'Read More';
                }
            });
        });
    }
    // closeForm function globally if needed
    window.closeForm = function(event) {
        if (event) event.preventDefault();
        document.getElementById("inquery_popUP")?.setAttribute('style', 'display:none');
        document.getElementById("tandc_view")?.setAttribute('style', 'display:none');
        $('#inquery_popUPoverlay').css('display', 'none');
        $('#can_pol').css('display', 'none');
        $('#pay_pol').css('display', 'none');
        $('.overlay_lay').css('display', 'none');
    };
    // ensure any original button stays working
    var origBookBtn = document.getElementById('book_now');
    if (origBookBtn && !origBookBtn.hasAttribute('data-listener')) {
        // keep original form submit
        origBookBtn.setAttribute('data-listener', 'true');
    }
    // maintain the package_person, etc all hidden but part of form submission
    // all fields are present but hidden using   class, this ensures server-side unchanged
    // also style for .  we already have
    // sticky update first left position
    setTimeout(function() {
        if (document.getElementById("myBtn").style.display === "block") {
            var leftPosition = (window.innerWidth - document.getElementById("myBtn").offsetWidth) / 2;
            document.getElementById("myBtn").style.left = leftPosition + "px";
        }
    }, 100);
</script>


<!-- live price calculation  -->
<script>
    let basePrice = <?php echo $package['price']; ?>;

    function updateTotal() {
        let total = basePrice;

        document.querySelectorAll('.addon-checkbox:checked').forEach(cb => {
            total += parseFloat(cb.getAttribute('data-price'));
        });

        document.getElementById('totalPrice').innerText = total.toLocaleString();
    }

    // Trigger on change
    document.querySelectorAll('.addon-checkbox').forEach(cb => {
        cb.addEventListener('change', updateTotal);
    });


    <?php if (isset($booking_success) && $booking_success): ?>
        window.open("<?php echo $whatsapp_link; ?>", "_blank");
    <?php endif; ?>

    <?php if (isset($booking_success) && $booking_success): ?>
        setTimeout(function() {
            window.location.href = "<?php echo $whatsapp_link; ?>";
        }, 500);
    <?php endif; ?>
</script>


<?php include './includes/footer.php' ?>


PK 99