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

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

$citation_instant_add   = isset($campoal_options['conikal_citation_instant_add_field']) ? $campoal_options['conikal_citation_instant_add_field'] : 'none';
$receive_update         = isset($campoal_options['conikal_receive_update_field']) ? $campoal_options['conikal_receive_update_field'] : 'checked';
$sign_anonymous         = isset($campoal_options['conikal_sign_anonymous_field']) ? $campoal_options['conikal_sign_anonymous_field'] : 'checked';
$reason_sign_box        = isset($campoal_options['conikal_reason_sign_box_field']) ? $campoal_options['conikal_reason_sign_box_field'] : 0;
$mobile_sign_style      = isset($campoal_options['conikal_mobile_sign_style_field']) ? $campoal_options['conikal_mobile_sign_style_field'] : 'button';
$sign_show_all          = isset($campoal_options['conikal_sign_show_all_field']) ? $campoal_options['conikal_sign_show_all_field'] : 0;

$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 current user avatar
$current_user_avatar        = conikal_get_avatar_url( $current_user->ID, array('size' => 64) );
$current_user_avatar_retina = conikal_get_avatar_url( $current_user->ID, array('size' => 128) );

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

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

// lazy load placeholder
$lazy_placeholder_avatar = conikal_lazy_load_placeholder('avatar');
?>

    <!-- SIGN THE PETITIN -->
    <?php if ($mobile_sign_style == 'sidebar' && $sign_show_all == 0) { ?>
        <div class="ui accordion accord-sign-options" id="accord-sign-options">
            <div class="title">
                <h4 class="ui header">
                <i class="dropdown icon"></i>
                    <?php esc_html_e('Options for sign', 'campoal') ?>
                </h4>
            </div>
            <div class="content">
    <?php } ?>
    <div class="ui secondary segment">
        <div class="ui list">
            <div class="item">
                <img class="ui avatar image lazy" data-src="<?php echo esc_url($current_user_avatar) ?>" data-retina="<?php echo esc_url($current_user_avatar_retina) ?>" src="<?php echo esc_url($lazy_placeholder_avatar) ?>">
                <div class="content">
                    <div class="header">
                        <?php echo esc_html($current_user->display_name); ?>
                    </div>
                    <div class="description">
                        <?php if ($current_user->user_country || $current_user->user_state || $current_user->user_city) { ?>
                            
                            <?php echo esc_html($current_user->user_city ? $current_user->user_city . ', ' : '') . esc_html($current_user->user_state ? $current_user->user_state . ', ' : '') . esc_html($current_user->user_country); ?>
                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <form class="ui form sign-petition-form" id="signPetitionForm<?php echo esc_attr($petition_id) ?>" data-id="<?php echo esc_attr($petition_id) ?>">
        <div class="field">
            <?php if ($reason_sign_box || !$citation) : ?>
            <div class="ui pointing below fluid basic large label sign-comment-label">
                <textarea name="signComment" id="sign-comment<?php echo esc_attr($petition_id) ?>" class="sign-comment" rows="4 " placeholder="<?php esc_attr_e('I am signing because...', 'campoal') ?>" data-id="<?php echo esc_attr($petition_id) ?>"></textarea>
            </div>
            <?php endif; ?>
            <div class="ui message sign-option">
                <div id="fb-publish<?php echo esc_attr($petition_id) ?>" class="fb-publish ui toggle checkbox <?php echo esc_attr($current_user->fb_publish == 1 ? 'checked' : ''); ?>" data-id="<?php echo esc_attr($petition_id) ?>">
                    <input type="checkbox" name="fbPublish" class="hidden" <?php echo esc_attr($current_user->fb_publish == 1 ? 'checked' : ''); ?>>
                    <label><i class="facebook icon"></i><?php esc_html_e('Share on Facebook', 'campoal') ?></label>
                </div>
            </div>
        </div>
        <?php if ($citation_instant_add != 'none' && $citation) { ?>
            <div class="field">
                <div class="ui message sign-option">
                    <div id="citation-instant<?php echo esc_attr($petition_id) ?>" class="citation-instant ui toggle checkbox <?php echo esc_attr(($citation_instant_add == 'checked' && $current_user->citation_instant == '') || $current_user->citation_instant != 0 ? 'checked' : ''); ?>" data-id="<?php echo esc_attr($petition_id) ?>">
                      <input type="checkbox" name="citationInstant" <?php echo esc_attr(($citation_instant_add == 'checked' && $current_user->citation_instant == '') || $current_user->citation_instant != 0 ? 'checked' : ''); ?>>
                      <label><?php esc_html_e('Add citation instantly', 'campoal') ?></label>
                    </div>
                </div>
            </div>
        <?php } ?>
        <?php if ($sign_anonymous != 'none') { ?>
            <div class="field">
                <div class="ui message sign-option">
                    <div id="sign-anonymous<?php echo esc_attr($petition_id) ?>" class="sign-anonymous ui toggle checkbox <?php echo esc_attr(($sign_anonymous == 'checked' && $current_user->anonymous == '') || $current_user->anonymous != 0 ? 'checked' : ''); ?>" data-id="<?php echo esc_attr($petition_id) ?>">
                      <input type="checkbox" name="signAnonymous" <?php echo esc_attr(($sign_anonymous == 'checked' && $current_user->anonymous == '') || $current_user->anonymous != 0 ? 'checked' : ''); ?>>
                      <label><?php esc_html_e('Display my name', 'campoal') ?></label>
                    </div>
                </div>
            </div>
        <?php } ?>
        <?php if ($receive_update != 'none') { ?>
            <div class="field">
                <div class="ui message sign-option">
                    <div id="email-notice<?php echo esc_attr($petition_id) ?>" class="email-notice ui toggle checkbox <?php echo esc_attr(($receive_update == 'checked' && $current_user->notice == '') || $current_user->notice != 0 ? 'checked' : ''); ?>" data-id="<?php echo esc_attr($petition_id) ?>">
                      <input type="checkbox" name="emailNotice" <?php echo esc_attr(($receive_update == 'checked' && $current_user->notice == '') || $current_user->notice != 0 ? 'checked' : ''); ?>>
                      <label><?php esc_html_e('Receive updates', 'campoal') ?></label>
                    </div>
                </div>
            </div>
        <?php } ?>
    </form>

    <?php if ($mobile_sign_style == 'sidebar' && $sign_show_all == 0) { ?>
            </div>  
        </div>
    <?php } ?>

    <div class="ui form citation-sidebar">
        <div class="field <?php echo esc_attr($citation ? 'display none' : '') ?>">
            <a href="javascript:void(0);" class="ui fluid primary big button signBtn signPetition" id="signBtn<?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) { ?>
            <?php get_template_part('templates/citation-opinion'); ?>
        <?php } ?>
    </div>
    