<!--  -->
<?php
    $html_id = pxl_get_element_id($settings);
    $select_post_by = 'post_selected';

    $post_ids = $widget->get_setting('source_'.$settings['post_type'].'_post_ids', '');
    $source = [];
    $orderby = $widget->get_setting('orderby', 'date');
    $order = $widget->get_setting('order', 'desc');
    $limit = $widget->get_setting('limit', 6);
    extract(pxl_get_posts_of_grid(
        'team', 
        [
            'source' => $source, 
            'orderby' => $orderby, 
            'order' => $order, 
            'limit' => $limit, 
            'post_ids' => $post_ids
        ],
        ''
    ));


    $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', '');

    $grid_class = 'pxl-grid-inner row';

    $pagination_type = $widget->get_setting('pagination_type', 'pagination');

    $post_type = $widget->get_setting('post_type','team');
    $layout = $widget->get_setting('layout_'.$post_type, 'team-1');

    // Animation
    $animate = $widget->get_setting('pxl_animate');
    $animate_delay = (int)$widget->get_setting('pxl_animate_delay', 0);

    $img_size = !empty($settings['img_size']) ? $settings['img_size'] : '767x1096';
?>
<?php if(count($posts) <= 0) : ?>
    <div class="pxl-no-post-found">
        <?php echo esc_html__( 'No Post Found', 'solarva' ); ?>
    </div>
<?php endif; ?>

<?php if($settings['layout_type'] === 'grid') : ?>
    <?php 
        $col_xs = 12 / intval($col_xs);
        $col_sm = 12 / intval($col_sm); 
        $col_md = 12 / intval($col_md);
        $col_lg = 12 / intval($col_lg);
        $col_xl = $settings['col_xl'] == '5' ? 'pxl5' : 12 / intval($col_xl);
        $col_xxl = $settings['col_xxl'] == '5' ? 'pxl5' : 12 / intval($col_xxl);
        $grid_class = 'pxl-grid-inner row';
        $pagination_type = $widget->get_setting('pagination_grid_type', 'pagination');
        $load_more = array(
            'post_type'       => $post_type,   
            'layout'          => $layout,
            'startPage'       => $paged,
            'maxPages'        => $max,
            'total'           => $total,
            'perpage'         => $limit,
            'nextLink'        => $next_link,
            'orderby'         => $orderby,
            'order'           => $order,
            'limit'           => $limit,
            'post_ids'        => $post_ids,
            'col_xxl'         => $col_xxl,
            'col_xl'          => $col_xl,
            'col_lg'          => $col_lg,
            'col_md'          => $col_md,
            'col_sm'          => $col_sm,
            'col_xs'          => $col_xs,
            'pagination_type' => $pagination_type,
            'img_size'        => $img_size,
            'animate'     => $animate,
            'animate_delay' => $animate_delay,
            'title_hover_style' => $settings['title_hover_style'],
        );
    
        $filter_grid_args = [
            'select_post_by' => $select_post_by,
            'grid_class' => $grid_class,
            'load_more' => $load_more,
            'pagination_type' => $pagination_type,
            'posts' => $posts,
            'query' => $query,
        ];
    
        $wrap_attrs = [
            'id'               => $html_id,
            'class'            => trim('pxl-grid pxl-post-grid pxl-team-grid pxl-team-grid2'),
            'data-start-page'  => $paged,
            'data-max-pages'   => $max,
            'data-total'       => $total,
            'data-perpage'     => $limit,
            'data-next-link'   => $next_link
        ];
    
        if ($pagination_type != 'false'){
            $wrap_attrs['data-loadmore'] = json_encode($load_more);
        }
        $widget->add_render_attribute( 'wrapper', $wrap_attrs );
    ?>
    <div <?php pxl_print_html($widget->get_render_attribute_string( 'wrapper' )) ?>>
        <div class="<?php echo esc_attr($grid_class); ?>" data-gutter="15">
            <?php solarva_get_post_grid($posts, $load_more); ?>
        </div>
        <?php if ($pagination_type == 'pagination') : ?>
            <div class="pxl-grid-pagination">
                <?php solarva()->page->get_pagination($query, true); ?>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>

<?php  if($settings['layout_type'] === 'carousel') : ?>
    <?php 
        $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'            => (int)$col_xxl,
            'slides_to_show_xl'             => (int)$col_xl,
            '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'              => 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)
        ]);
    ?>
    <div id="<?php echo esc_attr($html_id); ?>" class="pxl-swiper-slider pxl-team-carousel pxl-team-carousel2 ">
        <div class="pxl-carousel-inner">
            <div <?php pxl_print_html($widget->get_render_attribute_string('carousel')); ?>>
                <div class="pxl-swiper-wrapper">
                    <?php foreach ($posts as $key => $post):
                        $img_id = get_post_thumbnail_id($post->ID) ?? '';
                        $thumbnail = solarva_get_thumbnail($img_id, $img_size, false, 'layzyload');
                        $position = get_post_meta($post->ID, 'team_position', true);
                        $wow_delay = $key * $animate_delay;
                        $socials = get_team_socials($post->ID);

                    ?>
                        <!-- HTML -->
                        <div class="pxl-swiper-slide <?php echo esc_attr($animate); ?>" data-wow-delay="<?php echo esc_attr($wow_delay.'ms'); ?>">
                            <div class="pxl-post--container">
                                <div class="pxl-post--inner">
                                    <?php if(!empty($thumbnail)) : ?>
                                        <div class="pxl-post--featured pxl-hover-zoom-in">
                                            <a href="<?php echo esc_url(get_permalink($post->ID)); ?>" class="pxl-featured--link ">
                                                <?php pxl_print_html($thumbnail); ?>
                                            </a>
                                            <div class="pxl-item--socials">
                                                <?php if(!empty($socials)) : ?>
                                                    <?php foreach($socials as $social) : ?>
                                                        <?php if(($social['is_active'] === '1')) : ?>
                                                            <div class="pxl-item--social">
                                                                <a href="<?php echo esc_url($social['url']); ?>" class="pxl-social--link">
                                                                    <i class="<?php echo esc_attr($social['icon']); ?>"></i>
                                                                </a>
                                                            </div>
                                                        <?php endif; ?>
                                                    <?php endforeach; ?>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                    <div class="pxl-post--content">
                                        <div class="pxl-post--title  <?php echo esc_attr($settings['title_hover_style']); ?>">
                                            <a class="pxl-title--link" href="<?php echo esc_url(get_permalink($post->ID)); ?>">
                                                <?php echo esc_attr(get_the_title($post->ID)); ?>
                                            </a>
                                        </div>
                                        <?php if(!empty($position)) : ?>
                                            <span class="pxl-post--position">
                                                <?php echo esc_attr($position); ?>
                                            </span>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- HTML -->
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
        <?php if ($pagination): ?>
            <div class="pxl-swiper-dots-wrap">
                <div class="pxl-swiper-dots pxl-swiper-dots1"></div>
            </div>
        <?php endif; ?>
        <?php if ($arrows): ?>
            <div class="pxl-swiper-arrow-wrap">
                <div class="pxl-swiper-arrows pxl-swiper-arrows1">
                    <div class="pxl-swiper-arrow pxl-swiper-arrow-prev">
                        <svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="none">
                            <path d="M1.61719 7.96875L0.585938 9L8.83594 17.25L9.86719 16.2187L2.64844 9L9.86719 1.78125L8.83594 0.749998L4.71094 4.875L1.61719 7.96875Z" fill="#003973"/>
                        </svg>
                    </div>
                    <div class="pxl-swiper-arrow pxl-swiper-arrow-next">
                        <svg xmlns="http://www.w3.org/2000/svg" width="10" height="18" viewBox="0 0 10 18" fill="none">
                            <path d="M8.38281 10.0312L9.41406 9L1.07812 0.749998L0.046875 1.78125L7.26562 9L0.046875 16.2187L1.07812 17.25L5.28906 13.125L8.38281 10.0312Z" fill="#003973"/>
                        </svg>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>
