<?php
    $html_id = pxl_get_element_id($settings);

    // Grid
    $col_xs = $widget->get_setting('col_xs', '');
    $col_sm = $widget->get_setting('col_sm', '');
    $col_md = $widget->get_setting('col_md', '');
    $col_lg = $widget->get_setting('col_lg', '');
    $col_xl = $widget->get_setting('col_xl', '');
    $col_xxl = $widget->get_setting('col_xxl', '');
    
    // Animation
    $animate = $settings['pxl_animate'];
    $animate_delay = (int)$widget->get_setting('pxl_animate_delay', 0);;

    // Check
    $is_items = isset($settings['items']) && !empty($settings['items']) && count($settings['items']) || false;
    $layout_type = $settings['layout_type'];

    
    // Carousel
?>

<?php if ($is_items): ?>
    <?php if($layout_type === 'carousel'): ?>
        <?php 
            $pause_on_hover = !empty($settings['pause_on_hover']) || false;
            $autoplay = !empty($settings['autoplay']) || false;
            $autoplay_speed = !empty($settings['autoplay_speed']) ? $settings['autoplay_speed'] : 5000;
            $infinite = !empty($settings['infinite']) || false;
            $speed = !empty($settings['speed']) ? $settings['speed'] : 500;
            $arrows = !empty($settings['arrows']) || false;
            $pagination = !empty($settings['pagination']) || false;
            $pagination_type = $settings['pagination_carousel_type'];

            $opts = [
                'slide_direction'               => 'horizontal',
                'slide_percolumn'               => 1, 
                'slide_mode'                    => 'slide', 
                'slides_to_show'                => 1,
                'slides_to_show_xxl'            => $col_xxl,
                'slides_to_show_xl'             => $col_xl,
                'slides_to_show_lg'             => $col_lg,
                'slides_to_show_md'             => $col_md,
                'slides_to_show_sm'             => $col_sm,
                'slides_to_show_xs'             => $col_xs,
                'slides_to_scroll'              => 1,
                'arrow'                         => $arrows,
                'pagination'                    => $pagination,
                'pagination_type'               => $pagination_type,
                'autoplay'                      => $autoplay,
                'pause_on_hover'                => $pause_on_hover,
                'pause_on_interaction'          => true,
                'delay'                         => $autoplay_speed,
                'loop'                          => $infinite,
                'speed'                         => $speed
            ];    
            $widget->add_render_attribute( 'carousel', [
                'class'         => 'pxl-swiper-container',
                'dir'           => is_rtl() ? 'rtl' : 'ltr',
                'data-settings' => wp_json_encode($opts)
            ]);
        ?>
        <div id="<?php echo esc_attr($html_id); ?>" class="pxl-swiper-slider pxl-testimonial-carousel pxl-testimonial-carousel1 ">
            <div class="pxl-carousel-inner">
                <div <?php pxl_print_html($widget->get_render_attribute_string('carousel')); ?>>
                    <div class="pxl-swiper-wrapper">
                        <?php foreach ($settings['items'] as $key => $item): ?>
                            <?php  
                                $avatar = solarva_get_thumbnail($item['avatar']['id']); 
                                $desc = $item['desc'] ?? '';    
                                $name = $item['name'] ?? '';  
                                $position = $item['position'] ?? '';
                                $stars = $item['star_rating'] ?? 0;
                                $wow_delay = $key * $animate_delay;
                            ?>
                            <div class="pxl-swiper-slide <?php echo esc_attr($animate); ?>" data-wow-delay="<?php echo esc_attr($wow_delay.'ms'); ?>">
                                <div class="pxl-slide-container">
                                    <div class="pxl-slide-inner">
                                        <div class="pxl-content--left">
                                            <?php if(!empty($avatar)) : ?>
                                                <div class="pxl-item--avatar">
                                                    <?php pxl_print_html($avatar); ?>
                                                </div>
                                            <?php endif; ?>
                                            <div class="pxl-content-group pxl-group-copy">
                                                <div class="pxl-user-info">
                                                    <h3 class="pxl-user--name">
                                                        <?php echo esc_attr($name); ?>
                                                    </h3>
                                                    <span class="pxl-user--position">
                                                        <?php echo esc_attr($position); ?>
                                                    </span>
                                                </div>
                                                <?php if($stars > 0) : ?>
                                                    <div class="pxl-list--star">
                                                        <?php for($i=0; $i<$stars; $i++) : ?>
                                                            <svg class="pxl-item--star" width="24" height="23" viewBox="0 0 24 23" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                                <path d="M11.7417 18.4905L17.2833 21.8421C18.2981 22.4564 19.5399 21.5483 19.2729 20.4L17.804 14.0973L22.7046 9.85096C23.5993 9.07648 23.1186 7.60763 21.9435 7.51416L15.4939 6.96668L12.9702 1.01116C12.5162 -0.0704507 10.9672 -0.0704507 10.5132 1.01116L7.98945 6.95332L1.53986 7.5008C0.36478 7.59428 -0.115935 9.06313 0.778728 9.83761L5.67935 14.0839L4.2105 20.3866C3.94343 21.535 5.18528 22.443 6.20012 21.8288L11.7417 18.4905Z" fill="#FEC51B"/>
                                                            </svg>
                                                        <?php endfor; ?>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                        <div class="pxl-item--content pxl-content--right">
                                            <div class="pxl-item--desc">
                                                <?php echo esc_attr($desc); ?>
                                            </div>
                                            <div class="pxl-content-group">
                                                <div class="pxl-user-info">
                                                    <h3 class="pxl-user--name">
                                                        <?php echo esc_attr($name); ?>
                                                    </h3>
                                                    <span class="pxl-user--position">
                                                        <?php echo esc_attr($position); ?>
                                                    </span>
                                                </div>
                                                <?php if($stars > 0) : ?>
                                                    <div class="pxl-list--star">
                                                        <?php for($i=0; $i<$stars; $i++) : ?>
                                                            <svg class="pxl-item--star" width="24" height="23" viewBox="0 0 24 23" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                                <path d="M11.7417 18.4905L17.2833 21.8421C18.2981 22.4564 19.5399 21.5483 19.2729 20.4L17.804 14.0973L22.7046 9.85096C23.5993 9.07648 23.1186 7.60763 21.9435 7.51416L15.4939 6.96668L12.9702 1.01116C12.5162 -0.0704507 10.9672 -0.0704507 10.5132 1.01116L7.98945 6.95332L1.53986 7.5008C0.36478 7.59428 -0.115935 9.06313 0.778728 9.83761L5.67935 14.0839L4.2105 20.3866C3.94343 21.535 5.18528 22.443 6.20012 21.8288L11.7417 18.4905Z" fill="#FEC51B"/>
                                                            </svg>
                                                        <?php endfor; ?>
                                                    </div>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
            <?php if ($pagination): ?>
                <div class="pxl-swiper-dots-wrap">
                    <div class="pxl-swiper-dots pxl-swiper-dots1"></div>
                </div>
            <?php endif; ?>
            <?php if ($arrows): ?>
                <div class="pxl-swiper-arrow-wrap">
                    <div class="pxl-swiper-arrows pxl-swiper-arrows1">
                        <div class="pxl-swiper-arrow pxl-swiper-arrow-prev">
                            <svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="none">
                                <path d="M1.61719 7.96875L0.585938 9L8.83594 17.25L9.86719 16.2187L2.64844 9L9.86719 1.78125L8.83594 0.749998L4.71094 4.875L1.61719 7.96875Z" fill="#003973"/>
                            </svg>
                        </div>
                        <div class="pxl-swiper-arrow pxl-swiper-arrow-next">
                            <svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="none">
                                <path d="M8.38281 10.0312L9.41406 9L1.07812 0.749998L0.046875 1.78125L7.26562 9L0.046875 16.2187L1.07812 17.25L5.28906 13.125L8.38281 10.0312Z" fill="#003973"/>
                            </svg>
                        </div>
                    </div>
                </div>
            <?php endif; ?>
        </div>
        <?php return; ?>
    <?php endif; ?>
    <h4>
        <?php echo esc_html__('Coming Soon', 'solarva'); ?>
    </h4>
<?php else: ?>
    <h4>
        <?php echo esc_html__('Add item here.', 'solarva'); ?>
    </h4>
<?php endif; ?>


