<?php

function destination_cards_shortcode() {
            // Query pages with category "destination"
        $args = array(
            'post_type'      => 'page',
            'posts_per_page' => -1,
            'tax_query' => array(
                array(
                    'taxonomy' => 'page_category', // ← Correct taxonomy for pages
                    'field'    => 'slug',
                    'terms'    => 'experiences',
                ),
            ),
        );

    $query = new WP_Query($args);

    ob_start();

    if ($query->have_posts()) {
        echo '<div class="destination-cards-container">';
        echo '<h3 class="destination-cards-heading">Our Experiences</h3>';
        echo '<div class="destination-cards">';
        while ($query->have_posts()) {
            $query->the_post();
            $thumb = get_the_post_thumbnail_url(get_the_ID(), 'medium');
            $title = get_the_title();
            $link  = get_permalink();

            echo '<div class="destination-card">';
            if ($thumb) {
                echo '<a href="' . esc_url($link) . '"><img src="' . esc_url($thumb) . '" alt="' . esc_attr($title) . '"></a>';
            }
            echo '<p>' . esc_html($title) . '</p>';
            echo '</div>';
        }
        echo '</div>';
        echo '</div>';
    }

    wp_reset_postdata();

    return ob_get_clean();
}
add_shortcode('destination_cards', 'destination_cards_shortcode');

function destination_card_shortcode() {
    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'tax_query' => array(
            array(
                'taxonomy' => 'page_category',
                'field'    => 'slug',
                'terms'    => 'experiences',
            ),
        ),
    );
    $query = new WP_Query($args);

    ob_start();

    if ($query->have_posts()) {
        echo '<div class="travel-cards-container">';
        echo '<div class="travel-cards-grid">';
        while ($query->have_posts()) {
            $query->the_post();
            $thumb = get_the_post_thumbnail_url(get_the_ID(), 'large');
            $title = get_the_title();
            $link  = get_permalink();

            // Wrap everything inside the <a> so the whole card is clickable
            echo '<a href="' . esc_url($link) . '" class="travel-card">';
            if ($thumb) {
                echo '<div class="travel-image" style="background-image:url(' . esc_url($thumb) . ');"></div>';
            } else {
                echo '<div class="travel-image" style="background:#f0f0f0;"></div>';
            }
            echo '<div class="travel-overlay"><h3>' . esc_html($title) . '</h3></div>';
            echo '</a>';
        }
        echo '</div>';
        echo '</div>';
    }

    wp_reset_postdata();

    return ob_get_clean();
}
add_shortcode('destinations', 'destination_card_shortcode');



function safari_tabs_shortcode() {
    ob_start(); ?>

    <!-- Safari Packages Tabs -->
    <div class="safari-packages-tabs">

        <!-- Tab Nav -->
        <ul class="nav nav-tabs" id="safariTab" role="tablist">
            <li class="nav-item" role="presentation">
                <button class="nav-link active" id="uganda-tab" data-bs-toggle="tab" data-bs-target="#uganda" type="button" role="tab" aria-controls="uganda" aria-selected="true">
                    Uganda Safaris
                </button>
            </li>
            <li class="nav-item" role="presentation">
                <button class="nav-link" id="rwanda-tab" data-bs-toggle="tab" data-bs-target="#rwanda" type="button" role="tab" aria-controls="rwanda" aria-selected="false">
                    Rwanda Safaris
                </button>
            </li>
        </ul>

        <!-- Tab Content -->
        <div class="tab-content p-3 border border-top-0" id="safariTabContent">
            <div class="tab-pane fade show active" id="uganda" role="tabpanel" aria-labelledby="uganda-tab">
                <?php echo do_shortcode('[safari_packages category="uganda" limit="4"]'); ?>
            </div>
            <div class="tab-pane fade" id="rwanda" role="tabpanel" aria-labelledby="rwanda-tab">
                <?php echo do_shortcode('[safari_packages category="rwanda"]'); ?>
            </div>
            <P style="text-align:center;"><strong>Note:</strong>See more packages on the packages' pages</P>
        </div>
        

    </div>

    <?php
    return ob_get_clean();
}

// Register the shortcode
add_shortcode('safari_tabs', 'safari_tabs_shortcode');
