<?php

use ThemeAtelier\EventfulForElementor\Frontend\Helpers\EventfulForElementorFunctions;

if (! defined('ABSPATH')) exit; // Exit if accessed directly

/**
 * Item thumbnail
 *
 * This template can be overridden by copying it to yourtheme/eventful-por-elementor/templates/item/thumbnail.php
 *
 * @package    eventful-for-elementor
 * @subpackage eventful-for-elementor/src/Frontend/templates
 */

$lazy_load = isset($_post_thumb_setting['efpe_img_lazy_load']) ? $_post_thumb_setting['efpe_img_lazy_load'] : true;
$lazy_load = apply_filters('efpe_img_lazy_load', $lazy_load);

if ('carousel_layout' !== $layout && $lazy_load && !is_admin()) {
	wp_enqueue_script('efpe-lazyload');
	$image = sprintf('<img data-efpe_src="%1$s" %5$s class="efpe-lazyload" width="%2$s"  height="%3$s" alt="%4$s">', $thumb_url, $efpe_image_attr['width'], $efpe_image_attr['height'], $alter_text, $retina_img_attr);
} else {
	$image = sprintf('<img %5$s src="%1$s" width="%2$s" height="%3$s" alt="%4$s">', $thumb_url, $efpe_image_attr['width'], $efpe_image_attr['height'], $alter_text, $retina_img_attr);
}
?>

<div class="eventful__item--thumbnail">
	<?php if ('none' === $efpe_page_link_type) { ?>
		<a class="ta-efpe-thumb" aria-label="<?php echo esc_attr($efpe_image_attr['aria_label']); ?>" <?php echo esc_attr($efpe_link_rel_text); ?>>
		<?php } else { ?>
			<a class="ta-efpe-thumb" aria-label="<?php echo esc_attr($efpe_image_attr['aria_label']); ?>" href="<?php the_permalink($post); ?>" target="<?php echo esc_attr($efpe_link_target); ?>" <?php echo esc_attr($efpe_link_rel_text); ?>>
			<?php
		}
		if (empty($efpe_image_attr['video']) && empty($efpe_image_attr['audio'])) {
			echo wp_kses_post($image);
		} elseif ($efpe_image_attr['video']) {
			?>
				<div class='efpe-post-video-thumb-area'><?php echo wp_kses_post($efpe_image_attr['video']); ?></div>
			<?php
		} elseif ($efpe_image_attr['audio']) {
			?>
				<div class='efpe-post-audio-thumb-area'><?php echo wp_kses_post($efpe_image_attr['audio']); ?></div>
			<?php } ?>
			</a>
			<?php

			// Taxonomy terms over thumbnail.
			if ('category' === $post_thumb_meta) {
				ob_start();
				echo wp_kses($td['start'], $allow_tag);
				include EventfulForElementorFunctions::eventful_for_elementor_locate_template('item/post-thumb-taxonomy.php');
				echo wp_kses($td['end'], $allow_tag);
				$item_thumb = apply_filters('efpe_thumb_taxonomy', ob_get_clean());
				echo wp_kses_post($item_thumb);
			} elseif ('date' === $post_thumb_meta) {
				ob_start();
				echo wp_kses($td['start'], $allow_tag);
				include EventfulForElementorFunctions::eventful_for_elementor_locate_template('item/post-thumb-date.php');
				echo wp_kses($td['end'], $allow_tag);
				$item_thumb = apply_filters('efpe_thumb_archive', ob_get_clean());
				echo wp_kses_post($item_thumb);
			}
			?>

</div>