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

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

$default_accordion      = isset($campoal_options['conikal_default_accordion_sign_field']) ? $campoal_options['conikal_default_accordion_sign_field'] : 'share';
$common_donation_form  	= isset($campoal_options['conikal_common_donation_form_field']) ? $campoal_options['conikal_common_donation_form_field'] : 0;
$common_form_id     	= isset($campoal_options['conikal_common_form_id_field']) ? $campoal_options['conikal_common_form_id_field'] : 0;

$give_prefix 		    = '_give_';

$post_type = get_post_type($post->ID);
if ($post_type != 'give_forms') {
    $form_id = get_post_meta($post->ID, $post_type . '_post_id', true);
} else {
    $form_id = $post->ID;
}

if (!empty($common_donation_form) && !empty($common_form_id)) {
    $form_id    = $common_form_id;
}

$petition_id        = get_post_meta($form_id, $give_prefix . 'petition_id', true);

// check user has purchases
$user_contribute    = conikal_user_purchased_donation($form_id);
$reveal_label       = get_post_meta($form_id, '_give_reveal_label', true);

$give_attrs['id'] = $form_id;
$give_attrs['show_goal'] = false;
?>
<div class="<?php echo esc_attr(!wp_is_mobile() ? 'ui sticky donate-sticky give-packages-section' : 'give-packages-section') ?>" id="<?php echo esc_attr(!wp_is_mobile() ? 'donate-sticky' . esc_attr($form_id) : 'donate-sticky') ?>" data-id="<?php echo esc_attr($form_id) ?>" data-init="0">
    <?php get_template_part('templates/donation/donate-progress'); ?>
    <div class="ui divider"></div>
    <?php if ($user_contribute == false ) : ?>
            <?php echo give_form_shortcode($give_attrs) ?>
    <?php else : ?>
        <div class="ui accordion accord-share-facebook" data-id="<?php echo esc_attr($form_id) ?>">
            <?php if (isset($form_id) && !empty($form_id) && $reveal_label != '' && class_exists('Give')) { ?>
            <div class="title<?php echo esc_attr($default_accordion === 'contribute' && $user_contribute == false ? ' active' : '') ?>" data-id="<?php echo esc_attr($form_id) ?>">
                <h3 class="ui header">
                <i class="dropdown icon"></i>
                <?php echo esc_html($reveal_label) . esc_html__(' to project', 'campoal') ?>
                </h3>
            </div>
            <div class="content<?php echo esc_attr($default_accordion === 'contribute' && $user_contribute == false ? ' active' : '') ?>">
                <?php echo give_form_shortcode($give_attrs) ?>
            </div>
            <?php } ?>
            <div class="title<?php echo esc_attr($default_accordion === 'share' || $form_id === '' || $user_contribute == true || $reveal_label == '' ? ' active' : '') ?>" data-id="<?php echo esc_attr($form_id) ?>">
                <h3 class="ui header">
                <i class="dropdown icon"></i>
                <?php esc_html_e('Share this campaign', 'campoal') ?>
                </h3>
            </div>
            <div class="content<?php echo esc_attr($default_accordion === 'share' || $form_id === '' || $user_contribute == true || $reveal_label == '' ? ' active' : '') ?>">
                <?php get_template_part('templates/form/form-share', 'give'); ?>
            </div>
        </div>
    <?php endif; ?>
</div>
