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

global $post;

$give_prefix 		= '_give_';

$form_id 			= $post->ID;
$petition_id        = get_post_meta($form_id, $give_prefix . 'petition_id', true);
$lazy_placeholder   = conikal_lazy_load_placeholder('thumbnail');

if (empty($petition_id)) {
	$gallery 			= get_post_meta($form_id, $give_prefix . 'gallery', true);
	$images 			= conikal_get_gallery_images($gallery);
	$thumb_id 			= get_post_thumbnail_id($form_id);
	$thumbnail 			= wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
	$thumbnail_large 	= wp_get_attachment_image_src($thumb_id, 'large', true);
	$video 				= get_post_meta($form_id, $give_prefix . 'video', true);
	$thumb_placeholder 	= get_post_meta($form_id, $give_prefix . 'thumb', true);
	$thumb 				= get_post_meta($form_id, $give_prefix . 'thumb_small', true);
} else {
	$gallery 			= get_post_meta($petition_id, 'petition_gallery', true);
	$images 			= conikal_get_gallery_images($gallery);
	$thumb_id 			= get_post_thumbnail_id($petition_id);
	$thumbnail 			= wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
	$thumbnail_large 	= wp_get_attachment_image_src($thumb_id, 'large', true);
	$video 				= get_post_meta($petition_id, 'petition_video', true);
	$thumb_placeholder 	= get_post_meta($petition_id, 'petition_thumb', true);
	$thumb 				= get_post_meta($petition_id, 'petition_thumb_small', true);
}
?>

<div class="give-feature-thumbnail">
    <?php
        if (has_post_thumbnail(!empty($petition_id) ? $petition_id : $form_id)) { ?>
            <img class="ui fluid rounded image lazy" data-src="<?php echo esc_url($thumbnail_large[0]) ?>" src="<?php echo esc_url($lazy_placeholder) ?>" alt="<?php the_title_attribute() ?>">
        <?php } elseif ($video) { ?>
            <div class="ui embed media-embed" id="media-embed<?php echo esc_attr(!empty($petition_id) ? $petition_id : $form_id) ?>"></div>
            <input type="hidden" class="video-url" id="video-url<?php echo esc_attr(!empty($petition_id) ? $petition_id : $form_id) ?>" value="<?php echo esc_attr($video) ?>">
            <input type="hidden" class="thumb-url" id="thumb-url<?php echo esc_attr(!empty($petition_id) ? $petition_id : $form_id) ?>" value="<?php echo esc_attr($thumb_placeholder) ?>">
        <?php } elseif ($gallery) { ?>
            <img class="ui fluid rounded image lazy" data-src="<?php echo esc_url($images[1]) ?>" src="<?php echo esc_url($lazy_placeholder) ?>" alt="<?php the_title_attribute() ?>">
        <?php } else { ?>
            <img class="ui fluid bordered rounded image lazy" data-src="<?php echo esc_url($lazy_placeholder) ?>" src="<?php echo esc_url($lazy_placeholder) ?>" alt="<?php the_title_attribute() ?>">
    <?php } ?>
</div>