<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $campoal_options;
global $post;

$show_donors 				= isset($campoal_options['conikal_show_donors_section_field']) ? $campoal_options['conikal_show_donors_section_field'] : 0;
$recent_supporters 			= isset($campoal_options['conikal_recent_supporters_donors_field']) ? $campoal_options['conikal_recent_supporters_donors_field'] : 10;
$supporters_donors_style 	= isset($campoal_options['conikal_supporters_donors_style_field']) ? $campoal_options['conikal_supporters_donors_style_field'] : 'list';
$contributer_list_page 		= isset($campoal_options['conikal_page_supporters_list_field']) ? $campoal_options['conikal_page_supporters_list_field'] : 0;

$give_prefix 		= '_give_';

$form_id 			= $post->ID;
$backers            = give_get_form_sales_stats( $form_id );

if ( intval($backers) < $recent_supporters ) {
    $recent_supporters = $backers;
}

// all backer page
$contributer_list_page      = ($contributer_list_page ? get_permalink($contributer_list_page) : '');
$contributer_list_page      = add_query_arg(array('id' => $form_id, 'type' => 'donor'), $contributer_list_page);
?>

<?php if (isset($form_id) && !empty($form_id) && $show_donors == 1 && !empty($backers) && class_exists('Give')) : ?>
    <div class="give-backers-section">
        <div class="ui basic vertical segment donors-section" id="donors-section<?php echo esc_attr($form_id) ?>" data-id="<?php echo esc_attr($form_id) ?>" data-load="0">
            <h3 class="ui dividing header"><?php echo sprintf( _n('%s Backer', '%s Backers', $backers, 'campoal'), conikal_format_number('%!,0i', $backers) ) ?></h3>

            <?php
            if ($contributer_list_page && $supporters_donors_style == 'avatar') { ?>
                <div class="ui right floated tiny header">
                    <a href="<?php echo esc_url($contributer_list_page ? $contributer_list_page : '') ?>" class="text grey" data-bjax><?php esc_html_e('See more...', 'campoal') ?></a>
                </div>
            <?php } ?>

            <div id="recent-donors-list<?php echo esc_attr($form_id) ?>" class="donors-list <?php echo esc_attr($supporters_donors_style == 'avatar' ? 'ui mini images' : 'ui relaxed list') ?>">
            <?php for ($i=0; $i < $recent_supporters; $i++) { ?>
                <?php if ($supporters_donors_style == 'avatar') { ?>
                    <img class="ui image" alt="<?php esc_attr_e('Wireframe avatar loader', 'campoal') ?>" src="<?php echo esc_url(get_template_directory_uri() . '/images/wireframe-avatar-loader.svg') ?>">
                <?php } else { ?>
                    <div class="item">
                        <img class="ui image supporter-image-loader" alt="<?php esc_attr_e('Wireframe avatar loader', 'campoal') ?>" src="<?php echo esc_url(get_template_directory_uri() . '/images/wireframe-supporter-loader.svg') ?>">
                    </div>
                <?php } ?>
            <?php } ?>
            </div>

            <?php
            if ($contributer_list_page && $supporters_donors_style == 'list') { ?>
                <a href="<?php echo esc_url($contributer_list_page ? $contributer_list_page : '') ?>" class="text grey" data-bjax><?php esc_html_e('See more...', 'campoal') ?></a>
            <?php } ?>
        </div>
    </div>
<?php endif; ?>