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

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

$minimum_signature = isset($campoal_options['conikal_minimum_signature_field']) ? $campoal_options['conikal_minimum_signature_field'] : 0;

$petition_id = $post->ID;
$approve = get_post_status($petition_id);
$supporter_number = conikal_get_supporter_donors_number($petition_id);
$goal = $supporter_number->goal;
$sign_num = $supporter_number->sign;

// remove signature from email link
if (is_user_logged_in() && (isset($_GET['action']) && $_GET['action'] == 'remove_signature')) {
    $removed_signature = conikal_remove_signatures_link($current_user->ID, $petition_id);
} else {
    $removed_signature = false;
}
?>

<div class="ui basic vertical segment">
    <?php if (is_user_logged_in() && (get_the_author_meta('ID') == $current_user->ID || current_user_can('administrator') || current_user_can('editor') || conikal_co_author_permission($petition_id))) { ?>
        <?php if ($approve == 'pending') { ?>
            <div class="ui large warning message">
                <i class="warning icon"></i>
                <?php esc_html_e('Petition is pending approval!', 'campoal') ?>
            </div>
        <?php } ?>

        <?php if (isset($_GET['action']) && $_GET['action'] == 'update_pending') { ?>
            <div class="ui large warning message">
                <i class="warning icon"></i>
                <?php esc_html_e('Update just submitted for this petition is pending approval!', 'campoal') ?>
            </div>
        <?php } ?>

        <?php if ($sign_num < $minimum_signature) { ?>
            <div class="ui large warning message">
                <i class="warning icon"></i>
                <?php echo esc_html__('Getting to', 'campoal') . ' <strong>' . esc_html($minimum_signature) . '</strong> ' . esc_html__('signatures makes your petition visible to the whole community', 'campoal'); ?>
            </div>
        <?php } ?>
    <?php } ?>

    <?php if (is_user_logged_in() && (isset($_GET['action']) && $_GET['action'] == 'citation_pending')) { ?>
        <div class="ui large warning message">
            <i class="warning icon"></i>
            <?php esc_html_e('Citation just submitted for this petition is pending approval!', 'campoal') ?>
        </div>
    <?php } ?>

    <?php if ($removed_signature == true && (isset($_GET['action']) && $_GET['action'] == 'remove_signature')) { ?>
        <div class="ui large success message">
            <i class="check icon"></i>
            <?php echo sprintf(esc_html__('You has remove signature from %s successfully!', 'campoal'), esc_html($title)); ?>
        </div>
    <?php } elseif ($removed_signature == true && !is_user_logged_in() && (isset($_GET['action']) && $_GET['action'] == 'remove_signature')) { ?>
        <div class="ui large error message">
            <i class="ban icon"></i>
            <?php echo sprintf(esc_html__('Remove signature from %s failed!', 'campoal'), esc_html($title)); ?>
            <?php esc_html_e('You need', 'campoal') ?> <a href="javascript:void(0)" class="item signin-btn"><?php esc_html_e('Login', 'campoal') ?></a> <?php esc_html_e('to remove signature.', 'campoal') ?>
        </div>
    <?php } ?>
</div>
