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

global $campoal_options;
global $post;
global $current_user;
$show_letter = isset($campoal_options['conikal_show_letter_section_field']) ? $campoal_options['conikal_show_letter_section_field'] : 0;
$petition_comment = isset($campoal_options['conikal_petition_comment_field']) ? $campoal_options['conikal_petition_comment_field'] : 1;
$show_supporters            = isset($campoal_options['conikal_show_supporters_section_field']) ? $campoal_options['conikal_show_supporters_section_field'] : 0;

$petition_id = $post->ID;

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

// get fundraising mode setting
$fundraising_mode = conikal_fundraising_mode_setting($petition_id);

// get bookmarked
$bookmarks = get_user_meta($current_user->ID, 'petition_bookmark', true);
?>

<!-- MENU NAVIGATION -->
<?php if (!wp_is_mobile()) { ?>
<div class="ui sticky navigation-sticky" id="navigation-sticky<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>" data-init="0">
    <div class="ui pointing secondary menu navigation-menu" id="navigation-menu<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>">
        <a href="#story<?php echo esc_attr($petition_id) ?>" id="navlink-story<?php echo esc_attr($petition_id) ?>" class="item active"><?php esc_html_e('Story', 'campoal') ?></a>
        <?php if ($show_supporters == 1 && $fundraising_mode != 1) : ?>
            <a href="#supporters-section<?php echo esc_attr($petition_id) ?>" id="navlink-story<?php echo esc_attr($petition_id) ?>" class="item"><?php esc_html_e('Supporters', 'campoal') ?></a>
        <?php endif; ?>
        <?php if ($show_letter) : ?>
            <a href="#letter<?php echo esc_attr($petition_id) ?>" id="navlink-letter<?php echo esc_attr($petition_id) ?>" class="item"><?php esc_html_e('Letter', 'campoal') ?></a>
        <?php endif; ?>
        <?php if ($citation) : ?>
            <a href="#citations<?php echo esc_attr($petition_id) ?>" id="navlink-citations<?php echo esc_attr($petition_id) ?>" class="item"><?php esc_html_e('Citations', 'campoal') ?></a>
        <?php endif; ?>
        <a href="#updates<?php echo esc_attr($petition_id) ?>" id="navlink-update<?php echo esc_attr($petition_id) ?>" class="item"><?php esc_html_e('Updates', 'campoal') ?></a>
        <?php if(comments_open() && $petition_comment == 1) { ?>
        <a href="#comments<?php echo esc_attr($petition_id) ?>" id="navlink-comments<?php echo esc_attr($petition_id) ?>" class="item"><?php esc_html_e('Comments', 'campoal') ?></a>
        <?php } ?>
        <div class="right item">
        <?php if($bookmarks) {
                if(is_user_logged_in()) {
                    if(in_array($petition_id, $bookmarks) === false) {
                        echo '<a href="javascript:void(0)" class="bookmark-popup bookmarkPetition bookmarkBtn" id="bookmark-' . esc_attr($petition_id) . '" data-id="' . esc_attr($petition_id) . '" data-content="' . esc_attr__('Save this campaign', 'campoal') . '" data-position="top center" data-type="petition"><i class="bookmark outline icon"></i></a>';
                    } else {
                        echo '<a href="javascript:void(0)" class="bookmark-popup bookmarkedPetition bookmarkBtn" id="bookmark-' . esc_attr($petition_id) . '" data-id="' . esc_attr($petition_id) . '"  data-content="' . esc_attr__('Unsave this campaign', 'campoal') . '" data-position="top center" data-type="petition"><i class="bookmark icon"></i></a>';
                    }
                } else {
                    echo '<a href="javascript:void(0)" class="bookmark-popup signin-btn" data-content="' . esc_attr__('Save this campaign', 'campoal') . '" data-position="top center" data-type="petition"><i class="bookmark outline icon"></i></a>';
                }
            } else {
                if(is_user_logged_in()) {
                    echo '<a href="javascript:void(0)" class="bookmark-popup bookmarkPetition bookmarkBtn" id="bookmark-' . esc_attr($petition_id) . '" data-id="' . esc_attr($petition_id) . '" data-content="' . esc_attr__('Save this campaign', 'campoal') . '" data-position="top center" data-type="petition"><i class="bookmark outline icon"></i></a>';
                } else {
                    echo '<a href="javascript:void(0)" class="bookmark-popup signin-btn" data-content="' . esc_attr__('Save this campaign', 'campoal') . '" data-position="top center" data-type="petition"><i class="bookmark outline icon"></i></a>';
                }
        } ?>
        </div>
    </div>
</div>
<?php } ?>