<?php
/**
 * Template part for displaying Slider Section
 *
 * @package voltmaster-electrician
 */

$voltmaster_electrician_data_slick_speed = voltmaster_electrician_get_option('data_slick_speed');
$voltmaster_electrician_data_slick_infinite = voltmaster_electrician_get_option('data_slick_infinite');
$voltmaster_electrician_data_slick_dots = voltmaster_electrician_get_option('data_slick_dots');
$voltmaster_electrician_data_slick_autoplay = voltmaster_electrician_get_option('data_slick_autoplay');
$voltmaster_electrician_data_slick_draggable = voltmaster_electrician_get_option('data_slick_draggable');
$voltmaster_electrician_data_slick_fade = voltmaster_electrician_get_option('data_slick_fade');
$voltmaster_electrician_featured_slider_content_type = voltmaster_electrician_get_option('featured_slider_content_type');
$voltmaster_electrician_number_of_featured_slider_items = voltmaster_electrician_get_option('number_of_featured_slider_items');

$voltmaster_electrician_featured_slider_section_heading = voltmaster_electrician_get_option('featured_slider_section_heading');

?>


<?php
// Convert numeric options to boolean strings for slick carousel
$voltmaster_electrician_data_slick_infinite = $voltmaster_electrician_data_slick_infinite ? 'true' : 'false';
$voltmaster_electrician_data_slick_dots = $voltmaster_electrician_data_slick_dots ? 'true' : 'false';
$voltmaster_electrician_data_slick_autoplay = $voltmaster_electrician_data_slick_autoplay ? 'true' : 'false';
$voltmaster_electrician_data_slick_draggable = $voltmaster_electrician_data_slick_draggable ? 'true' : 'false';
$voltmaster_electrician_data_slick_fade = $voltmaster_electrician_data_slick_fade ? 'true' : 'false';
?>

<div id="featured-slider">
    <div class="section-content "
        data-slick='{"slidesToShow": 1, "slidesToScroll": 1, "infinite": <?php echo esc_attr($voltmaster_electrician_data_slick_infinite); ?>, "speed": <?php echo esc_attr($voltmaster_electrician_data_slick_speed); ?>, "dots": <?php echo esc_attr($voltmaster_electrician_data_slick_dots); ?>, "autoplay": <?php echo esc_attr($voltmaster_electrician_data_slick_autoplay); ?>, "draggable": <?php echo esc_attr($voltmaster_electrician_data_slick_draggable); ?>, "fade": <?php echo esc_attr($voltmaster_electrician_data_slick_fade); ?> }'>

        <?php
        $voltmaster_electrician_number_of_featured_slider_items = absint(get_theme_mod('number_of_featured_slider_items', 5)); // Ensure the value is an integer
        
        // Ensure the number of posts starts from 1, and not showing any extras
        if ($voltmaster_electrician_number_of_featured_slider_items < 1) {
            $voltmaster_electrician_number_of_featured_slider_items = 1; // Ensure minimum value is 1
        }

        ?> <?php $voltmaster_electrician_slider_pages = array();
         for ($voltmaster_electrician_count = 1; $voltmaster_electrician_count <= 4; $voltmaster_electrician_count++) {
             $voltmaster_electrician_mod = intval(get_theme_mod('select_post_slider' . $voltmaster_electrician_count));
             if ('page-none-selected' != $voltmaster_electrician_mod) {
                 $voltmaster_electrician_slider_pages[] = $voltmaster_electrician_mod;
             }
         }
         if (!empty($voltmaster_electrician_slider_pages)):
             $voltmaster_electrician_args = array(
                 'post_type' => 'post',
                 'post__in' => $voltmaster_electrician_slider_pages,
                 'posts_per_page' => $voltmaster_electrician_number_of_featured_slider_items,
                 'orderby' => 'post__in'
             );
             $voltmaster_electrician_catquery = new WP_Query($voltmaster_electrician_args);

             $voltmaster_electrician_catquery_counter = 0; // Initialize counter
             while ($voltmaster_electrician_catquery->have_posts() && $voltmaster_electrician_catquery_counter < $voltmaster_electrician_number_of_featured_slider_items):
                 $voltmaster_electrician_catquery->the_post();
                 $voltmaster_electrician_catquery_counter++;
                 ?>
                <article>


                    <div class="container mx-auto px-4 sm:px-6 lg:px-8 relative z-10 pt-48">
                        <div class="grid lg:grid-cols-2 gap-12 items-center">


                            <div class="text-white space-y-8">
                                <div class="row d-flex align-items-center">
                                    <div class="slider-inner-mainbox">
                                        <?php if (get_theme_mod('featured_slider_overlayimg_enable', true)): ?>
                                            <!-- Additional content if enabled -->
                                        <?php endif; ?>
                                        <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12 leftcontentbox <?php echo esc_attr(get_theme_mod('voltmaster_electrician_featured_slider_onload_effects', 'wow zoomIn')); ?>"
                                            data-wow-duration="2s">


                                            <div class="wrapper animated <?php echo esc_attr(get_theme_mod('voltmaster_electrician_featured_slider_onload_effects', 'wow Bounce In Up')); ?>"
                                                data-wow-duration="2s">
                                                <div class="entry-container">
                                                    <header class="entry-header header">
                                                        <h3><i
                                                                class="fa-solid fa-bolt w-6 h-4 text-yellow-400"></i><?php echo ($voltmaster_electrician_featured_slider_section_heading); ?>
                                                        </h3>
                                                        <div class="read-more">
                                                            <?php
                                                            $title = get_the_title();
                                                            $title_words = explode(' ', $title);

                                                            if (count($title_words) > 1) {
                                                                // First word + Second word with color + Rest words
                                                                $first_word = $title_words[0];
                                                                $second_word = '<span style="color: #fac100;">' . $title_words[1] . '</span>';
                                                                $remaining_words = implode(' ', array_slice($title_words, 2));
                                                                $final_title = trim($first_word . ' ' . $second_word . ' ' . $remaining_words);
                                                            } else {
                                                                $final_title = $title; // In case there's only one word
                                                            }
                                                            ?>

                                                            <h2 class="entry-title"
                                                                style="text-transform: <?php echo esc_attr(get_theme_mod('featured_slider_title_case', 'none')); ?>;">
                                                                <?php echo $final_title; ?>
                                                            </h2>
                                                            <div class="p"> <?php $voltmaster_electrician_excerpt = voltmaster_electrician_the_excerpt(25);
                                                            echo wp_kses_post(wpautop($voltmaster_electrician_excerpt)); ?>
                                                            </div>
                                                            <?php
                                                            $stars = get_theme_mod('voltmaster-electrician_rating_stars', 5);
                                                            $rating_text = get_theme_mod('voltmaster-electrician_rating_text', '5.0 Rating (150+ Reviews)');
                                                            ?>

                                                            <div class="rating d-flex align-items-center">
                                                                <?php for ($i = 1; $i <= 5; $i++): ?>
                                                                    <?php if ($i <= $stars): ?>
                                                                        <i class="fa fa-star"
                                                                            style="color: #fac100; font-size: 20px; margin-right: 3px;"></i>
                                                                    <?php else: ?>
                                                                        <i class="fa fa-star"
                                                                            style="color: #ccc; font-size: 20px; margin-right: 3px;"></i>
                                                                    <?php endif; ?>
                                                                <?php endfor; ?>

                                                                <span style="color: #fff; margin-left: 8px;">
                                                                    <?php echo esc_html($rating_text); ?>
                                                                </span>
                                                            </div>












                                                        </div>
                                                    </header>
                                                    <div class="button flex flex-col sm:flex-row gap-4 mt-5">
                                                        <a href="<?php echo esc_url(get_theme_mod('voltmaster_electrician_button1_url', '#')); ?>"
                                                            class="btn1 btn-custom1 rounded1 py-2 px-3 text-sm" style="font-size: 0.875rem;
line-height: 1.25rem; 
font-weight: 600; "><i class="fa-solid fa-phone"></i>
                                                            <?php echo esc_html(get_theme_mod('voltmaster_electrician_button1_text', 'Call Now: (555) 123-4567')); ?>
                                                        </a>
                                                        <a href="<?php echo esc_url(get_theme_mod('voltmaster_electrician_button2_url', '#')); ?>"
                                                            class="btn1 btn-custom1 rounded2 py-2 px-3 text-sm" style="font-size: 0.875rem;
line-height: 1.25rem; 
font-weight: 600; "><i class="fa-regular fa-file"></i>
                                                            <?php echo esc_html(get_theme_mod('voltmaster_electrician_button2_text', 'Get Free Quote')); ?>
                                                        </a>



                                                    </div>

                                                </div><!-- .wrapper -->
                                            </div><!-- .leftcontentbox -->


                                        </div><!-- .slider-inner-mainbox -->
                                    </div><!-- .row -->
                                </div><!-- .slide-inner -->
                            </div>

                            
                            <div class="relative">
                                <div class="sliderimg rounded-2xl shadow-2xl" style="overflow: hidden;">
                                    <?php if (has_post_thumbnail()): ?>
                                        <?php $voltmaster_electrician_total_slider_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full'); ?>
                                        <img class="slide-mainimg" alt="<?php echo esc_attr(get_the_title()); ?>"
                                            src="<?php echo esc_url($voltmaster_electrician_total_slider_image[0]); ?>"
                                            class="w-full h-[600px] object-cover ">
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>


                </article>
            <?php endwhile; ?>
        <?php endif; ?>
        <?php wp_reset_postdata(); ?>
    </div><!-- .section-content -->
</div>