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

global $post;
global $campoal_options;
$common_donation_form  	= isset($campoal_options['conikal_common_donation_form_field']) ? $campoal_options['conikal_common_donation_form_field'] : 0;
$common_form_id     	= isset($campoal_options['conikal_common_form_id_field']) ? $campoal_options['conikal_common_form_id_field'] : 0;

$give_prefix 		    = '_give_';

// Does the user want category?
$enable_category    = give_is_setting_enabled( give_get_option( 'categories', 'disabled' ) );

$form_id 			    = $post->ID;
if (!empty($common_donation_form) && !empty($common_form_id)) {
    $form_id    = $common_form_id;
}

$petition_id            = get_post_meta($form_id, $give_prefix . 'petition_id', true);
$backers                = give_get_form_sales_stats( $form_id );
$categories 		    = wp_get_post_terms($form_id, 'give_forms_category');

$goal_option        = get_post_meta($form_id, $give_prefix . 'goal_option', true);
$raise_number       = conikal_get_supporter_donors_number($form_id, 'donor', true);

if (!empty($petition_id)) {
    if(!is_array($categories) || !isset($categories[0])) {
		$categories     = wp_get_post_terms($petition_id, 'petition_category', true);
	}
}
?>
<div class="give-feature-footer">
    <?php if (give_is_setting_enabled( $goal_option )) : ?>
        <div class="ui tiny header">
            <?php echo sprintf( esc_html__('%1$s of %2$s raised', 'campoal'), esc_html($raise_number->sign_format), esc_html($raise_number->goal_format) ) ?>
        </div>
        <div class="ui tiny primary progress petition-goal" data-value="<?php echo esc_attr($raise_number->sign) ?>" data-total="<?php echo esc_attr($raise_number->goal) ?>">
            <div class="bar">
                <div class="progress"></div>
            </div>
        </div>
        <div class="ui hidden fitted divider"></div>
    <?php endif; ?>
    <div class="ui grid">
        <div class="nine wide column">
            <span class="ui primary label">
                <?php echo (empty($backers)) ? esc_html_e('No Backer', 'campoal') : conikal_custom_icon('supporter') . sprintf(_n('%s backer', '%s backers', $backers, 'campoal'), conikal_format_number('%!,0i', $backers, true)); ?>
            </span>
        </div>
        <div class="seven wide right aligned column">
            <?php if ($enable_category && is_array($categories)) { ?>
                <div class="ui labels give-category-label">
                    <?php foreach($categories as $category) { ?>
                        <a href="<?php echo get_term_link($category->term_id) ?>" class="ui label" data-bjax><?php echo esc_html($category->name) ?></a>
                    <?php } ?>
                </div>
            <?php } ?>
        </div>
    </div>
</div>