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

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

$button_style = isset($campoal_options['conikal_citation_button_style_field']) ? $campoal_options['conikal_citation_button_style_field'] : 'one';
$citation_fact_score = isset($campoal_options['conikal_citation_fact_score_field']) ? $campoal_options['conikal_citation_fact_score_field'] : 'all';

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

// get custom sign button label
$sign_button_text        = conikal_custom_sign_label_button($petition_id);

// get petition citation status
$citation_apply = isset($campoal_options['conikal_citation_apply_field']) ? $campoal_options['conikal_citation_apply_field'] : 'single';
if ($citation_apply == 'global') {
    $citation = isset($campoal_options['conikal_citation_field']) ? $campoal_options['conikal_citation_field'] : 1;
} else {
    $petition_citation = get_post_meta($petition_id, 'petition_citation_status', true);
    $citation = isset($campoal_options['conikal_citation_field']) ? ($petition_citation != '' ? $petition_citation : $campoal_options['conikal_citation_field']) : 1;
} ?>

<?php if ($button_style == 'one') { ?>
<div class="field citation-opinion" id="citation-opinion<?php echo esc_attr($petition_id) ?>">
  	<input type="radio" name="citation_opinion<?php echo esc_attr($petition_id) ?>" id="yes<?php echo esc_attr($petition_id) ?>" value="yes" checked />
  	<input type="radio" name="citation_opinion<?php echo esc_attr($petition_id) ?>" id="no<?php echo esc_attr($petition_id) ?>" value="no" />
  	<div class="switch">
    	<label for="yes<?php echo esc_attr($petition_id) ?>" id="opinion-yes" class="citation-opinion-btn" data-id="<?php echo esc_attr($petition_id) ?>"><?php esc_html_e('Agree', 'campoal') ?></label>
    	<label for="no<?php echo esc_attr($petition_id) ?>" id="opinion-no" class="citation-opinion-btn" data-id="<?php echo esc_attr($petition_id) ?>"><?php esc_html_e('Disagree', 'campoal') ?></label>
    	<span></span>
  	</div>
</div>
<?php } elseif ($button_style == 'two') { ?>
  <div class="field stv-radio-buttons-wrapper citation-opinion" id="citation-opinion<?php echo esc_attr($petition_id) ?>">
    <div class="stv-radio-buttons-wrapper">
      <input type="radio" class="stv-radio-button" name="citation_opinion<?php echo esc_attr($petition_id) ?>" value="yes" id="yes<?php echo esc_attr($petition_id) ?>" checked />
      <label class="ui large button citation-opinion-btn citation-yes" for="yes<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>">
        <?php echo conikal_custom_icon('agree') ?>
        <?php esc_html_e('Agree', 'campoal') ?>
      </label>
      <input type="radio" class="stv-radio-button" name="citation_opinion<?php echo esc_attr($petition_id) ?>" value="no" id="no<?php echo esc_attr($petition_id) ?>" />
      <label class="ui large button citation-opinion-btn citation-no" for="no<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>">
        <?php echo conikal_custom_icon('disagree') ?>
        <?php esc_html_e('Disagree', 'campoal') ?>
      </label>
    </div>
  </div>
<?php } ?>
<div class="field <?php echo esc_attr($citation ? '' : 'display none') ?>">
    <a href="javascript:void(0);" class="ui fluid primary big button citationBtn" id="citationBtn<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>">
      <?php echo conikal_custom_icon('sign') ?><?php echo esc_html($sign_button_text) ?>  
    </a>
</div>
<?php if ( $citation_fact_score == 'all' || ($citation_fact_score == 'mobile' && wp_is_mobile()) || ($citation_fact_score == 'desktop' && !wp_is_mobile()) ) :
  $citation_opinion = conikal_citation_fact_score($petition_id); ?>
  <div class="field">
    <div class="ui tiny progress fact-score-status-<?php echo esc_attr(intval($citation_opinion->score) >= 50 ? 'agree' : 'disagree') ?> citation-opinion-progress" id="citation-opinion-progress<?php echo esc_attr($petition_id) ?>" data-value="<?php echo esc_attr($citation_opinion->yes) ?>" data-total="<?php echo esc_attr($citation_opinion->total) ?>"> 
        <div class="bar">
          <div class="progress"></div>
        </div>
        <div class="label"><?php esc_html_e('Fact score: ', 'campoal') ?> <span id="citation-fact-score<?php echo esc_attr($petition_id) ?>"><?php echo esc_html($citation_opinion->score) ?></span><?php esc_html_e('%', 'campoal') ?></div>
    </div>
  </div>
<?php endif; ?>
<div class="ui hidden divider"></div>

