<?php
$carousel_settings = kaitex_carousel_header($widget, array());

$img_size = $widget->get_setting('img_size', 'full');

if ( ! empty( $settings['link']['url'] ) ) {
    $widget->add_render_attribute( 'link', 'href', $settings['link']['url'] );

    if ( $settings['link']['is_external'] ) {
        $widget->add_render_attribute( 'link', 'target', '_blank' );
    }
    if ( $settings['link']['nofollow'] ) {
        $widget->add_render_attribute( 'link', 'rel', 'nofollow' );
    }
}

if(isset($settings['list']) && !empty($settings['list']) && count($settings['list'])): ?>
    <div class="pxl-swiper-sliders pxl-instagram-carousel pxl-instagram-carousel1 pxl-parent-cursor <?php echo esc_attr($settings['style']); ?> <?php echo esc_attr($settings['pxl_animate']); ?>" data-wow-delay="<?php echo esc_attr($settings['pxl_animate_delay']); ?>ms" data-wow-duration="<?php echo esc_attr($settings['pxl_animate_duration']); ?>s" data-arrow="<?php echo esc_attr($carousel_settings['arrows']); ?>">
        <?php if(!empty($settings['title'])) : ?>
            <div class="container-custom pxl-middle">
                <div class="pxl-item--title pxl-element-parallax">
                    <?php if ( ! empty( $settings['link']['url'] ) ) { ?><a <?php pxl_print_html($widget->get_render_attribute_string( 'link' )); ?>><?php } ?>
                        <?php echo pxl_print_html($settings['title']); ?>
                    <?php if ( ! empty( $settings['link']['url'] ) ) { ?></a><?php } ?>
                </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['list'] as $key => $value):
                        $image = isset($value['image']) ? $value['image'] : '';
                        $btn_link = isset($value['btn_link']) ? $value['btn_link'] : '';
                        $link_key = $widget->get_repeater_setting_key( 'btn_link', 'value', $key );
                        if ( ! empty( $btn_link['url'] ) ) {
                            $widget->add_render_attribute( $link_key, 'href', $btn_link['url'] );

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

                            if ( $btn_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">
                                <?php if ( !empty($image['id']) ) :
                                    $img_icon  = pxl_get_image_by_size( array(
                                        'attach_id'  => $image['id'],
                                        'thumb_size' => $img_size,
                                    ) );
                                    $thumbnail_icon = $img_icon['thumbnail']; ?>
                                    <?php if(!empty($btn_link['url'])) { ?> <a <?php echo implode( ' ', [ $link_attributes ] ); ?>> <?php } ?>
                                        <div class="pxl-item--image">
                                            <?php echo pxl_print_html($thumbnail_icon); ?>
                                        </div>
                                    <?php if (!empty($btn_link['url'])) { ?></a><?php } ?>
                                <?php endif; ?>
                           </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
            <?php kaitex_carousel_footer($carousel_settings['arrows'], $carousel_settings['arrows_style'], $carousel_settings['pagination'], $carousel_settings['bullets_style']); ?>
        </div>
    </div>
<?php endif; ?>
