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

global $campoal_options;
global $post;
global $current_user;

$prompt_action = isset($campoal_options['conikal_prompt_action_field']) ? $campoal_options['conikal_prompt_action_field'] : 1;

$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;
}

$link = get_permalink($petition_id);
$supporter_number = conikal_get_supporter_donors_number($petition_id);
$goal = $supporter_number->goal;
$status = get_post_meta($petition_id, 'petition_status', true);

// get form option
$form_id = get_post_meta($petition_id, 'petition_contribute', true);
$contribute_approve = get_post_status($form_id);
if ($contribute_approve != 'publish') {
    $form_id = '';
}
$reveal_label = get_post_meta($form_id, '_give_reveal_label', true);
$donation_num = give_get_form_sales_stats( $form_id );

// get petition citation status
$citation = conikal_citation_status($petition_id);

// check user has purchases
$user_contribute = conikal_user_purchased_donation($form_id);
?>

<div class="ui bottom sidebar segment sign-sidebar" id="sign-sidebar<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>" data-closed="0">
    <div class="ui grid mobile only">
        <div class="sixteen wide column">
        <?php get_template_part('templates/donation/donate-progress', 'mobile'); ?>
        <div class="ui fifted divider"></div>
        <?php
            if($user_contribute == false && (int)$donation_num < (int)$goal && (int)$status == 0) {
                get_template_part('templates/donation/donate-action');
            } else {
                get_template_part('templates/sign-share/share', 'mobile');
            }
        
        wp_nonce_field('share_ajax_nonce', 'securityShare' . $petition_id, true); ?>
        <input type="hidden" id="petition_id<?php echo esc_attr($petition_id) ?>" value="<?php echo esc_attr($petition_id) ?>">
        <input type="hidden" id="petition_url<?php echo esc_attr($petition_id) ?>" value="<?php echo esc_attr($link) ?>">
        </div>
    </div>
</div>

<!-- MOBILE SIGN PETITION BUTTON -->
<div class="ui sticky mobile-sign-btn" id="mobile-sign-btn<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>">
    <div class="ui attached segment">
        <div class="ui grid mobile only">
            <div class="sixteen wide column">
                <?php if($user_contribute == false && (int)$donation_num < (int)$goal && (int)$status == 0) { ?>
                    <button class="ui primary fluid large button"><?php echo conikal_custom_icon('sign') ?><?php echo sprintf(esc_html__('%s to campaign', 'campoal'), $reveal_label) ?></button>
                <?php } else { ?>
                    <button class="ui primary fluid large button"><?php echo conikal_custom_icon('share') ?><?php esc_html_e('Share this Campaign', 'campoal') ?></button>
                <?php } ?>
            </div>
        </div>
    </div>
</div>


<!-- ACTION AFTER SIGN -->
<?php 
    if ($citation) {
        // get modal submit citation
        get_template_part('templates/citation-modal');
    }
?>

<!-- PROMPT ACTION MODAL -->
<?php if ($prompt_action && $user_contribute == false) {
    // get modal submit citation
    $prompt_action_remind = isset($_COOKIE['conikal_prompt_action_remind']) ? $_COOKIE['conikal_prompt_action_remind'] : 0;
    if ($prompt_action_remind != 1) { 
        get_template_part('templates/prompt-action');
    }
} ?>