<?php
$default_settings = [
    'layout_mode' => 'fitRows',
];
$settings = array_merge($default_settings, $settings);
extract($settings);

$img_size = '';
if(!empty($settings['img_size'])) {
    $img_size = $settings['img_size'];
} else {
    $img_size = 'full';
}?>
<?php if(isset($settings['partner']) && !empty($settings['partner']) && count($settings['partner'])): ?>
<div class="pxl-grid pxl-partner pxl-partner2" data-layout="<?php echo esc_attr($layout_mode); ?>">
    <div class="pxl-grid-inner pxl-grid-masonry row" data-gutter="15">    
        <div class="pxl-item--outer">        
            <?php foreach ($settings['partner'] as $key => $value):
             $title = isset($value['title']) ? $value['title'] : '';
             $image = isset($value['image']) ? $value['image'] : '';
             $image_dark = isset($value['darkmode_image']) ? $value['darkmode_image'] : '';
             $link = isset($value['link']) ? $value['link'] : '';
             $item_cls = [ 'elementor-repeater-item-'.$value['_id'] ];               
             $link_key = $widget->get_repeater_setting_key( 'title', 'value', $key );
             if ( ! empty( $link['url'] ) ) {
                $widget->add_render_attribute( $link_key, 'href', $link['url'] );

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

                if ( $link['nofollow'] ) {
                    $widget->add_render_attribute( $link_key, 'rel', 'nofollow' );
                }
            }
            $link_attributes = $widget->get_render_attribute_string( $link_key );
            ?>                
            <div class="pxl-item--inner <?php echo implode(' ', $item_cls) ?> <?php echo esc_attr($settings['pxl_animate']); ?>" data-wow-delay="<?php echo esc_attr($settings['pxl_animate_delay']); ?>ms">
                <div class="pxl-item--image">
                    <?php if ( ! empty( $link['url'] ) ) { ?><a <?php echo implode( ' ', [ $link_attributes ] ); ?>><?php } ?>
                    <?php if(!empty($image['id'])) {
                        $img = pxl_get_image_by_size( array(
                            'attach_id'  => $image['id'],
                            'thumb_size' => $img_size,
                            'class' => 'image-light no-lazyload',
                        ));
                        $thumbnail = $img['thumbnail'];?>
                        <?php echo wp_kses_post($thumbnail); ?>
                    <?php } ?>
                    <?php if ( ! empty( $link['url'] ) ) { ?></a><?php } ?>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
</div>
</div>
<?php endif; ?>
