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

global $campoal_options;
global $post;

$mobile_progress_bar = isset($campoal_options['conikal_mobile_progress_bar_field']) ? $campoal_options['conikal_mobile_progress_bar_field'] : 'sidebar';

$post_type = get_post_type($post->ID);
if ($post_type != 'petition') {
    $petition_id = get_post_meta($post->ID, $post_type . '_post_id', true);
} else {
    $petition_id = $post->ID;
}

$supporter_number = conikal_get_supporter_donors_number($petition_id);
$goal = $supporter_number->goal;
$sign_num = $supporter_number->sign;
$status = get_post_meta($petition_id, 'petition_status', true);
?>

<?php if ((int)$sign_num >= (int)$goal || (int)$status == 1) { ?>
    <div class="ui grid">
        <div class="thirteen wide column">
            <div class="ui medium header sign-section-title text victory">
                <?php echo conikal_custom_icon('victory_inverse') ?>
                <div class="content">
                    <?php ( (int)$status == 1 ? esc_html_e('Confirm Victory!', 'campoal') : esc_html_e('Victory!', 'campoal') ); ?>
                </div>
            </div>
        </div>
        <div class="three wide right aligned column">
            <a href="javascript:void(0)" class="font big close-mobile-sign" id="close-mobile-sign<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>"><i class="angle down icon"></i></a>
        </div>
    </div>
    <?php if ($mobile_progress_bar == 'sidebar' || $mobile_progress_bar == 'both') { ?>
    <div class="ui indicating tiny victory progress petition-goal" id="petition-goal<?php echo esc_attr($petition_id) ?>" data-value="<?php echo esc_attr($goal) ?>" data-total="<?php echo esc_attr($goal) ?>">
        <div class="bar">
            <div class="progress"></div>
        </div>
        <div class="label">
            <span>
                <?php echo sprintf(esc_html__( _n('This petition won with %s supporter', 'This petition won with %s supporters', $sign_num, 'campoal') ), conikal_format_number('%!,0i', esc_html($sign_num))); ?>
            </span>
        </div>
    </div>
    <?php } ?>
<?php } elseif ((int)$status == 2) { ?>
    <div class="ui grid">
        <div class="thirteen wide column">
            <div class="ui mediumm header sign-section-title">
                <i class="lock icon"></i>
                <div class="content">
                    <?php esc_html_e('Petition closed', 'campoal') ?>
                </div>
            </div>
        </div>
        <div class="three wide right aligned column">
            <a href="javascript:void(0)" class="font big close-mobile-sign" id="close-mobile-sign<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>"><i class="angle down icon"></i></a>
        </div>
    </div>
    <?php if ($mobile_progress_bar == 'sidebar' || $mobile_progress_bar == 'both') { ?>
    <div class="ui tiny progress petition-goal" id="petition-goal<?php echo esc_attr($petition_id) ?>" data-value="<?php echo esc_attr($sign_num) ?>" data-total="<?php echo esc_attr($goal) ?>">
        <div class="bar">
            <div class="progress"></div>
        </div>
        <div class="label">
            <span class="ned_no" id="ned_no<?php echo esc_attr($petition_id) ?>">
                <?php echo conikal_format_number('%!,0i', esc_html($goal - $sign_num)) ?>
            </span> 
            <?php echo esc_html__('needed to reach', 'campoal') . ' ' . conikal_format_number('%!,0i', esc_html($goal)) ?>
        </div>
    </div>
    <?php } ?>
<?php } else { ?>
    <div class="ui grid">
        <div class="thirteen wide column">
            <div class="ui medium header sign-section-title">
                <?php echo conikal_custom_icon('supporter') ?>
                <div class="content">
                    <span class="fav_no" id="fav_no<?php echo esc_attr($petition_id) ?>"  data-id="<?php echo esc_attr($petition_id) ?>">
                        <?php echo conikal_format_number('%!,0i', esc_html($sign_num)) ?>
                    </span> 
                    <?php echo esc_html__( _n('Supporter', 'Supporters', $sign_num, 'campoal') ) ?>
                </div>
            </div>
        </div>
        <div class="three wide right aligned column">
            <a href="javascript:void(0)" class="font big close-mobile-sign" id="close-mobile-sign<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>"><i class="angle down icon"></i></a>
        </div>
    </div>
    <?php if ($mobile_progress_bar == 'sidebar' || $mobile_progress_bar == 'both') { ?>
    <div class="ui indicating tiny primary progress petition-goal" id="petition-goal<?php echo esc_attr($petition_id) ?>" data-value="<?php echo esc_attr($sign_num) ?>" data-total="<?php echo esc_attr($goal) ?>">
        <div class="bar">
            <div class="progress"></div>
        </div>
        <div class="label">
            <span class="ned_no" id="ned_no<?php echo esc_attr($petition_id) ?>">
                <?php echo conikal_format_number('%!,0i', esc_html($goal - $sign_num)) ?>
            </span> 
            <?php echo esc_html__('needed to reach', 'campoal') . ' ' . conikal_format_number('%!,0i', esc_html($goal)) ?>
        </div>
    </div>
    <?php } ?>
<?php } ?>
            