<?php
$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', '');
if($col_xxl == 'inherit') {
    $col_xxl = $col_xl;
}

$col_thumbs_xs = $widget->get_setting('col_thumbs_xs', '');
$col_thumbs_sm = $widget->get_setting('col_thumbs_sm', '');
$col_thumbs_md = $widget->get_setting('col_thumbs_md', '');
$col_thumbs_lg = $widget->get_setting('col_thumbs_lg', '');
$col_thumbs_xl = $widget->get_setting('col_thumbs_xl', '');
$col_thumbs_xxl = $widget->get_setting('col_thumbs_xxl', '');
if($col_thumbs_xxl == 'inherit') {
    $col_thumbs_xxl = $col_thumbs_xl;
}

$slides_to_scroll = $widget->get_setting('slides_to_scroll');
$arrows = $widget->get_setting('arrows', false);  
$pagination = $widget->get_setting('pagination', false);
$pagination_type = $widget->get_setting('pagination_type', 'bullets');
$pause_on_hover = $widget->get_setting('pause_on_hover', false);
$autoplay = $widget->get_setting('autoplay', false);
$autoplay_speed = $widget->get_setting('autoplay_speed', 5000);
$infinite = $widget->get_setting('infinite', false);  
$speed = $widget->get_setting('speed', 500);
$drap = $widget->get_setting('drap', false);
$opts = [
    'slide_direction'               => 'horizontal',
    'slide_percolumn'               => 1, 
    'slide_mode'                    => 'slide', 
    'slides_to_show'                => (int)$col_xl,
    'slides_to_show_xxl'            => (int)$col_xxl, 
    'slides_to_show_lg'             => (int)$col_lg, 
    'slides_to_show_md'             => (int)$col_md, 
    'slides_to_show_sm'             => (int)$col_sm, 
    'slides_to_show_xs'             => (int)$col_xs, 
    'slides_to_scroll'              => (int)$slides_to_scroll,
    'arrow'                         => (bool)$arrows,
    'pagination'                    => (bool)$pagination,
    'pagination_type'               => $pagination_type,
    'autoplay'                      => (bool)$autoplay,
    'pause_on_hover'                => (bool)$pause_on_hover,
    'pause_on_interaction'          => true,
    'delay'                         => (int)$autoplay_speed,
    'loop'                          => (bool)$infinite,
    'speed'                         => (int)$speed
];

$opts_thumb = [
    'slide_direction'               => 'horizontal',
    'slides_to_show_thumbs'         => (int)$col_thumbs_xl,
    'slides_to_show_thumbs_xxl'     => (int)$col_thumbs_xxl, 
    'slides_to_show_thumbs_lg'      => (int)$col_thumbs_lg, 
    'slides_to_show_thumbs_md'      => (int)$col_thumbs_md, 
    'slides_to_show_thumbs_sm'      => (int)$col_thumbs_sm, 
    'slides_to_show_thumbs_xs'      => (int)$col_thumbs_xs, 
    'slide_mode'                    => 'slide',
    'slides_to_scroll'              => (int)$slides_to_scroll,
    'loop'                          => false,
];


$widget->add_render_attribute( 'thumb', [
    'class'         => 'pxl-swiper-thumbs',
    'data-settings' => wp_json_encode($opts_thumb)
]);

$widget->add_render_attribute( 'carousel', [
    'class'         => 'pxl-swiper-container',
    'dir'           => is_rtl() ? 'rtl' : 'ltr',
    'data-settings' => wp_json_encode($opts)
]);
if(isset($settings['testimonial']) && !empty($settings['testimonial']) && count($settings['testimonial'])): 
    $is_new = \Elementor\Icons_Manager::is_migration_allowed();
    $image_size = !empty($settings['img_size']) ? $settings['img_size'] : 'full';?>
    <div class="pxl-swiper-slider pxl-slider-carousel pxl-slider-carousel1 <?php echo esc_attr($settings['pxl_animate']); ?>"data-wow-delay="<?php echo esc_attr($settings['pxl_animate_delay']); ?>ms" <?php if($drap !== false) : ?>data-cursor-drap="<?php echo esc_html__('DRAG', 'aimo'); ?>"<?php endif; ?>>
        <div class="pxl-item--mask ">
            <?php $img_icon  = pxl_get_image_by_size( array(
                    'attach_id'  => $settings['image_mask']['id'],
                    'thumb_size' => 'full',
                ) );
                $thumbnail_icon    = $img_icon['thumbnail'];
                $thumbnail_url = $img_icon['url']; ?>
                <div class="pxl-item--image bg-image" style="background-image: url(<?php echo esc_url($thumbnail_url); ?>);">
                </div>
        </div>
        <div class="pxl-carousel-inner">
            <div <?php pxl_print_html($widget->get_render_attribute_string( 'carousel' )); ?>>
                <div class="pxl-swiper-wrapper wrapper1">
                    <?php foreach ($settings['testimonial'] as $key => $value):
                        $title = isset($value['title']) ? $value['title'] : '';
                        $sub_title = isset($value['sub_title']) ? $value['sub_title'] : '';
                        $text = isset($value['text']) ? $value['text'] : '';
                        $button = isset($value['button']) ? $value['button'] : '';
                       

                        $link_key = $widget->get_repeater_setting_key( 'link', 'value', $key );
                        if ( ! empty( $value['link']['url'] ) ) {
                            $widget->add_render_attribute( $link_key, 'href', $value['link']['url'] );

                            if ( $value['link']['is_external'] ) {
                                $widget->add_render_attribute( $link_key, 'target', '_blank' );
                            }

                            if ( $value['link']['nofollow'] ) {
                                $widget->add_render_attribute( $link_key, 'rel', 'nofollow' );
                            }
                        }
                        $link_attributes = $widget->get_render_attribute_string( $link_key ); 

                        ?>
                        <div class="pxl-swiper-slide ">
                            <div class="pxl-item--inner ">
                                <div class="pxl-item--holder pxl-item--flexnw">
                                    <div class="pxl-item--meta">
                                        <div class="pxl-content">
                                            <div class="pxl-item--sub el-empty wow PXLfadeInUp" data-wow-delay="300ms" ><?php echo pxl_print_html($sub_title); ?></div>
                                            <h5 class="pxl-item--title el-empty wow PXLfadeInUp" data-wow-delay="500ms"><?php echo pxl_print_html($title); ?></h5>
                                        </div>
                                        <div class="pxl-item--desc el-empty wow PXLfadeInUp" data-wow-delay="700ms"><?php echo pxl_print_html($text); ?></div>
                                        <a class="pxl-item-link btn wow PXLfadeInUp" data-wow-delay="900ms" <?php echo implode( ' ', [ $link_attributes ] ); ?>><?php ?>
                                            <?php echo pxl_print_html($button); ?>
                                        </a>
                                    </div>
                                </div>
                           </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
            <div <?php pxl_print_html($widget->get_render_attribute_string( 'thumb' )); ?>>
                <div class="pxl-swiper-wrapper wrapper2">
                    <?php foreach ($settings['testimonial'] as $key => $value):
                        $image = isset($value['image']) ? $value['image'] : '';
                        ?>
                        <div class="pxl-swiper-slide">
                            <div class="pxl-item-inner">
                                <div class="pxl-image wow skewIn" data-wow-delay="500ms">
                                    <?php if(!empty($image['id'])) { 
                                        $img = pxl_get_image_by_size( array(
                                            'attach_id'  => $image['id'],
                                            'thumb_size' => $image_size,
                                            'class' => 'no-lazyload',
                                        ));
                                        $thumbnail = $img['thumbnail'];

                                        $img_url = pxl_get_image_by_size( array(
                                            'attach_id'  => $image['id'],
                                            'thumb_size' => 'full',
                                            'class' => 'no-lazyload',
                                        ));
                                        $thumbnail_url = $img_url['url']; ?>
                                        <?php echo wp_kses_post($thumbnail); ?>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
            <div class="pxl-icon-social">
                    <?php foreach ($settings['icons'] as $key => $value):
                        $icon_key = $widget->get_repeater_setting_key( 'pxl_icon', 'icons', $key );
                        $widget->add_render_attribute( $icon_key, [
                            'class' => $value['pxl_icon'],
                            'aria-hidden' => 'true',
                        ] );
                        $link_key1 = $widget->get_repeater_setting_key( 'icon_link', 'value', $key );
                        if ( ! empty( $value['icon_link']['url'] ) ) {
                            $widget->add_render_attribute( $link_key1, 'href', $value['icon_link']['url'] );

                            if ( $value['icon_link']['is_external'] ) {
                                $widget->add_render_attribute( $link_key1, 'target', '_blank' );
                            }

                            if ( $value['icon_link']['nofollow'] ) {
                                $widget->add_render_attribute( $link_key1, 'rel', 'nofollow' );
                            }
                        }
                        $link_attributes = $widget->get_render_attribute_string( $link_key1 ); ?>
                        <?php if ( ! empty( $value['pxl_icon'] ) ) : ?>
                            <a <?php echo implode( ' ', [ $link_attributes ] ); ?>>
                                <?php if ( $is_new ):
                                    \Elementor\Icons_Manager::render_icon( $value['pxl_icon'], [ 'aria-hidden' => 'true' ] );
                                elseif(!empty($value['pxl_icon'])): ?>
                                    <i class="<?php echo esc_attr( $value['pxl_icon'] ); ?>" aria-hidden="true"></i>
                                <?php endif; ?>
                            </a>
                        <?php endif; ?>
                    <?php endforeach; ?>
                </div>
        </div>
        <div class="pxl-pagination">
            <div class="pxl-swiper-dot">
                <?php if($arrows !== false): ?>
                    <div class="pxl-swiper-arrow-wrap style-1">
                        <div class="pxl-swiper-arrow pxl-swiper-arrow-prev pxl-cursor--cta">
                            <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="white">
                                <path d="M12.9447 11.0003V5.19531L2.05469 12.0003L12.9397 18.8053V13.0003H21.9397V11.0003H12.9447ZM10.9447 11.0003V13.0003V15.1953L5.82969 12.0003L10.9447 8.80531V11.0003Z"/>
                            </svg>
                        </div>
                        <div class="pxl-swiper-arrow pxl-swiper-arrow-next pxl-cursor--cta">
                            <svg xmlns="http://www.w3.org/2000/svg" width="20" height="14" viewBox="0 0 20 14" fill="white">
                                <path d="M9.05469 6.00031H0.0546875V8.00031H9.05469V13.8053L19.9447 7.00031L9.05469 0.195312V6.00031ZM11.0547 8.00031V6.00031V3.80531L16.1697 7.00031L11.0547 10.1953V8.00031Z"/>
                            </svg>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if($pagination !== false): ?>
                    <div class="pxl-swiper-dots style-1"></div>
                <?php endif; ?>
            </div>   
        </div>                               
    </div>
<?php endif; ?>
