<?php
if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
?>
<div class="rivax-authors-list">
<?php
$args = [];
if($settings['authors_list'] == 'top') {
    $max = intval($settings['max_authors']) ?: 3;
    $args = ['fields' => [ 'ID','display_name' ], 'has_published_posts' => 'post', 'orderby' => 'post_count', 'order' => 'DESC', 'number' => $max ];
}
else {
    $ids = $settings['manual_authors'];
    if(!empty($ids)) {
        $args = ['include' => $ids, 'fields' => [ 'ID','display_name' ], 'orderby' => 'post_count', 'order' => 'DESC'];
    }
}

if(!empty($args)) {
    $authors = get_users( $args );
    if(!empty($authors)) {
        foreach ($authors as $author) {
            echo '<div class="author">';
                echo get_avatar( $author->ID, 80 );
                echo '<div class="content">';
                    echo '<span class="name">' . esc_html($author->display_name) .'</span>';
                    if($settings['Show_job_position']) {
                        $job_position = get_user_meta($author->ID, 'rivax_author_position', true);
                        if($job_position) {
	                        echo '<span class="position">' . esc_html($job_position) .'</span>';
                        }
                    }
                    if($settings['show_count'] && $settings['count_position'] == 'below') {
                        echo '<span class="count">' . count_user_posts($author->ID, 'post', true) . esc_html($settings['count_text']) .'</span>';
                    }
                echo '</div>';

                if($settings['show_count'] && $settings['count_position'] == 'front') {
                    echo '<span class="count">' . count_user_posts($author->ID, 'post', true) . esc_html($settings['count_text']) .'</span>';
                }

                if($settings['link']) {
                    echo '<a class="rivax-position-cover" href="' . get_author_posts_url($author->ID) . '" title="' . esc_attr($author->display_name) . '"' . ($settings['open_link_new_tab'] ? ' target="_blank"' : '') . '></a>';
                }
            echo '</div>';
        }
    }
}
?>
</div>
