<?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;
}
$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);  
$show_star = $widget->get_setting('show_star');

$opts = [
    'slide_direction'               => 'horizontal',
    'slide_percolumn'               => 1, 
    'slide_mode'                    => 'fade', 
    'slides_to_show'                => 1,
    'slides_to_show_xxl'            => 1, 
    'slides_to_show_lg'             => 1, 
    'slides_to_show_md'             => 1, 
    'slides_to_show_sm'             => 1, 
    'slides_to_show_xs'             => 1, 
    'slides_to_scroll'              => 1,
    '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
];
$widget->add_render_attribute( 'carousel', [
    'class'         => 'pxl-swiper-container',
    'dir'           => is_rtl() ? 'rtl' : 'ltr',
    'data-settings' => wp_json_encode($opts)
]);

$opts_thumb = [
    'slide_direction'               => 'horizontal',
    'slides_to_show'                => 4,
    'slide_mode'                    => 'slide',
    'loop'                          => false,
];
$widget->add_render_attribute( 'thumb', [
    'class'         => 'pxl-swiper-thumbs',
    'data-settings' => wp_json_encode($opts_thumb)
]);

?>
<?php if(isset($settings['item_lv2']) && !empty($settings['item_lv2']) && count($settings['item_lv2'])): 
    $image_size = !empty($settings['img_size']) ? $settings['img_size'] : '640x556'; ?>
    <div class="pxl-swiper-slider pxl-carousel-custom pxl-carousel-custom2 pxl-swiper-boxshadow"data-view-auto="<?php echo esc_attr($col_xl); ?>" <?php if($drap !== false) : ?>data-cursor-drap="<?php echo esc_html('DRAG', 'hubsteel'); ?>"<?php endif; ?>>
        <?php if($arrows !== false): ?>
            <div class="pxl-inner-top">
                <div class="pxl-swiper-arrow-wrap style-5">
                    <div class="pxl-swiper-arrow pxl-swiper-arrow-prev">
                        <div class="hover">
                            <svg id="Layer_1" enable-background="new 0 0 20 20" height="512" viewBox="0 0 20 20" width="512" xmlns="http://www.w3.org/2000/svg"><path d="m12 2-1.4 1.4 5.6 5.6h-16.2v2h16.2l-5.6 5.6 1.4 1.4 8-8z" fill="rgb(0,0,0)"/></svg>
                        </div>
                    </div>
                    <div <?php pxl_print_html($widget->get_render_attribute_string( 'thumb' )); ?>>
                        <div class="pxl-swiper-wrapper swiper-wrapper">
                            <?php foreach ($settings['item_lv2'] as $key => $value):
                                $categori = isset($value['categori']) ? $value['categori'] : '';
                                if($key < 6) : ?>
                                    <div class="pxl-swiper-slide swiper-slide">
                                        <div class="pxl-item--inner">
                                            <div class="pxl-testtiminial-meta">
                                                <div class="pxl-item-categori"><?php echo pxl_print_html($categori); ?></div>
                                            </div>
                                        </div>
                                    </div>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </div>
                    </div>
                    <div class="pxl-swiper-arrow pxl-swiper-arrow-next">
                        <div class="hover">
                            <svg id="Layer_1" enable-background="new 0 0 20 20" height="512" viewBox="0 0 20 20" width="512" xmlns="http://www.w3.org/2000/svg"><path d="m12 2-1.4 1.4 5.6 5.6h-16.2v2h16.2l-5.6 5.6 1.4 1.4 8-8z" fill="rgb(0,0,0)"/></svg>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <div class="pxl-carousel-inner">
            <div <?php pxl_print_html($widget->get_render_attribute_string( 'carousel' )); ?>>
                <div class="pxl-swiper-wrapper">
                    <?php foreach ($settings['item_lv2'] as $key => $value):
                        $title_lv2 = isset($value['title_lv2']) ? $value['title_lv2'] : '';
                        $text_list1 = isset($value['text_list1']) ? $value['text_list1'] : '';
                        $text_list2 = isset($value['text_list2']) ? $value['text_list2'] : '';
                        $text_list3 = isset($value['text_list3']) ? $value['text_list3'] : '';
                        $image_lv2 = isset($value['image_lv2']) ? $value['image_lv2'] : '';
                        $desc_lv2 = isset($value['desc_lv2']) ? $value['desc_lv2'] : '';
                        $title_btn = isset($value['title_btn']) ? $value['title_btn'] : '';
                        $link_key = $widget->get_repeater_setting_key( 'link_btn', 'value', $key );
                        if ( ! empty( $value['link_btn']['url'] ) ) {
                            $widget->add_render_attribute( $link_key, 'href', $value['link_btn']['url'] );

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

                            if ( $value['link_btn']['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-testtiminial-meta">
                                    <div class="pxl-inner-title">
                                        <h5 class="pxl-item--title"><?php echo pxl_print_html($title_lv2); ?></h5>
                                        <div class="pxl-item--desc"><?php echo pxl_print_html($desc_lv2); ?></div>
                                        <ul class="pxl-list">
                                            <li class="pxl-item-list"><?php echo pxl_print_html($text_list1); ?></li>
                                            <li class="pxl-item-list"><?php echo pxl_print_html($text_list2); ?></li>
                                            <li class="pxl-item-list"><?php echo pxl_print_html($text_list3); ?></li>
                                        </ul>
                                    </div>
                                    <?php if(!empty($image_lv2['id'])) { 
                                        $img = pxl_get_image_by_size( array(
                                            'attach_id'  => $image_lv2['id'],
                                            'thumb_size' => $image_size,
                                            'class' => 'no-lazyload',
                                        ));
                                        $thumbnail = $img['thumbnail'];
                                        ?>
                                        <div class="pxl-item--imgprimary">
                                            <?php echo wp_kses_post($thumbnail); ?>
                                            <a <?php echo implode( ' ', [ $link_attributes ] ); ?>>
                                                <svg xmlns="http://www.w3.org/2000/svg" fill="#000" height="512" viewBox="0 0 24 24" width="512"><path d="m16.0039 9.414-8.60699 8.607-1.414-1.414 8.60599-8.607h-7.58499v-2h10.99999v11h-2z" fill="rgb(0,0,0)"></path></svg>
                                            </a>
                                        </div>
                                    <?php } ?>
                                </div>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php if($pagination !== false): ?>
            <div class="pxl-swiper-dots style-1"></div>
        <?php endif; ?>
    </div>
<?php endif; ?>

