<?php
    // 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
    $opts = [];
    if($layout_type === 'carousel') {
        $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)
    ]);

    $widget->add_render_attribute( 'counter', [
        'class' => 'pxl-number--value effect-default',
        'data-duration' => 2000,
        'data-startnumber' => 1,
        'data-endnumber' => $settings['number'],
        'data-to-value' => $settings['number'],
        'data-delimiter' => '',
    ]); 

?>

<?php if ($is_items): ?>
    <?php if($layout_type === 'carousel'): ?>
        <div class="pxl-swiper-slider pxl-testimonial-carousel pxl-testimonial-carousel3 ">
            <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 
                                $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-item--desc">
                                            <?php echo esc_attr($item['desc']); ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
                <div class="pxl-content-group">
                    <div class="pxl-item--list">
                        <?php foreach($settings['items'] as $key => $item) : ?>
                            <?php 
                                $avatar_thumbnail = solarva_get_thumbnail($item['avatar']['id']);    
                            ?>
                            <div class="pxl-item--single">
                                <?php pxl_print_html($avatar_thumbnail); ?>
                            </div>
                        <?php endforeach; ?>
                        <div class="pxl-item--single pxl-item--counter">
                            <div class="pxl-item--number">
                                <span 
                                    <?php pxl_print_html($widget->get_render_attribute_string( 'counter' )); ?>>
                                    <?php echo esc_html($settings['number']); ?>
                                </span>
                                <?php if(!empty($settings['suffix'])) : ?>
                                    <span class="pxl-item--suffix"><?php echo pxl_print_html($settings['suffix']); ?></span>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                    <?php if(!empty($settings['label'])) : ?>
                        <div class="pxl-item--label">
                            <?php echo esc_attr($settings['label']); ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </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; ?>


