<?php
/**
 * Liting the slider/trainer details
 * @param : int $pageId default is null
 * @param : boolean $isCustomizer default is false, if set to true will get the data stored with customizer
 * @param : int $i default is null, it will used as a iteration for data with customizer, this will be used only if the $isCustomizer is set to true.
 * @return: Text $text
 */ 
 
// Slider shortcode with Swiper
function luzuk_slider_shortcode2($pageId = null, $isCustomizer = false, $i = null) {

    // Define plugin version for cache busting
    $plugin_version = '0.0.5';

    // Enqueue Swiper CSS and JS
    wp_register_style('lmslider_fontawesome_style', plugins_url('../assets/css/font-awesome.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('lmslider_fontawesome_style');

    wp_register_style('lmslider_fontawesomeall_style', plugins_url('../assets/css/fontawesome-all.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('lmslider_fontawesomeall_style');

    wp_register_style('ls_slider2_css', plugins_url('../assets/css/slider2.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('ls_slider2_css');

    wp_register_style('swiper_css', plugins_url('../assets/css/swiperbundle.css', __FILE__), array(), $plugin_version);
    wp_enqueue_style('swiper_css');

    wp_register_script('swiper_js', plugin_dir_url(__FILE__) . '../assets/js/swiperbundle.js', array('jquery'), $plugin_version, true);
    wp_enqueue_script('swiper_js');

    wp_register_script('swiper_script', plugins_url('../assets/js/swiperscript.js', __FILE__), array(), $plugin_version, true);
    wp_enqueue_script('swiper_script');
    
    
    ob_start();

    $args = array('post_type' => 'lmslider_our_slider');
    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    }
    $args['posts_per_page'] = -1;

    $query = new WP_Query($args);
    if ($query->have_posts()) :
?>

<section id="slider-section" class="slider-area home-slider">
    <section class="hero-slider hero-style">
        <div class="swiper-container">
            <div class="swiper-wrapper">

                <?php
                while ($query->have_posts()) : $query->the_post();
                    $luzuk_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
                    $post = get_post();

                    // Button 1
                    $buttonlabel = get_post_meta($post->ID, 'buttonlabel', false);
                    $sliderluzuk_buttonlabel = !empty($buttonlabel[0]) ? $buttonlabel[0] : '';

                    $buttonlink = get_post_meta($post->ID, 'buttonlink', false);
                    $sliderluzuk_buttonlink = !empty($buttonlink[0]) ? $buttonlink[0] : '';

                    // Button 2
                    $buttonlabel1 = get_post_meta($post->ID, 'buttonlabel1', false);
                    $sliderluzuk_buttonlabel1 = !empty($buttonlabel1[0]) ? $buttonlabel1[0] : '';

                    $buttonlink1 = get_post_meta($post->ID, 'buttonlink1', false);
                    $sliderluzuk_buttonlink1 = !empty($buttonlink1[0]) ? $buttonlink1[0] : '';
                ?>

                <div class="swiper-slide">
                    <div class="slide-inner slide-bg-image">
                        <div class="sliderimg wow zoomIn">
                            <?php if (has_post_thumbnail()) : ?>
                                <img class="slide-mainimg" alt="<?php echo esc_html(get_the_title()); ?>" src="<?php echo esc_url($luzuk_image[0]); ?>">
                            <?php endif; ?>
                            <div class="slider-shape"></div>
                        </div>

                        <div class="slider-content">
                            <div class="title wow bounceInDown">
                                <?php echo esc_html(get_the_title()); ?>
                            </div>
                            <div class="sub-title wow bounceInLeft">
                                <p><?php echo esc_html(wp_strip_all_tags(apply_filters('the_content', get_the_content()))); ?></p>
                            </div>
                            <div class="slider-btn">
                                <ul>
                                    <?php if (!empty($sliderluzuk_buttonlabel)) : ?>
                                        <li>
                                            <a class="sliderbuton1" href="<?php echo esc_url($sliderluzuk_buttonlink); ?>">
                                                <span><?php echo esc_html($sliderluzuk_buttonlabel); ?></span>
                                            </a>
                                        </li>
                                    <?php endif; ?>
                                    <?php if (!empty($sliderluzuk_buttonlabel1)) : ?>
                                        <li>
                                            <a class="sliderbuton2" href="<?php echo esc_url($sliderluzuk_buttonlink1); ?>">
                                                <span><?php echo esc_html($sliderluzuk_buttonlabel1); ?></span>
                                            </a>
                                        </li>
                                    <?php endif; ?>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>

                <?php endwhile; ?>
                <?php wp_reset_postdata(); ?>
            </div>

            <!-- Swiper Controls -->
            <div class="swiper-pagination"></div>
            <div class="swiper-button-next"><i class="fa-solid fa-angle-right"></i></div>
            <div class="swiper-button-prev"><i class="fa-solid fa-angle-left"></i></div>
        </div>
    </section>
</section>

<?php
    endif;

    $text = ob_get_contents();
    ob_clean();
    return $text;
}

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

// Shortcode
add_shortcode('lms_expert_teacher', 'luzuk_slider_shortcode2');