<?php
/**
 * Post single gallery template part
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
 *
 * @package WordPress
 * @subpackage BookYourTravel
 * @since 1.0
 * @version 8.00
 */
global $entity_obj;

$images = $entity_obj->get_images();

if ($images && count($images) > 0) {

	$image_sources = array();

	for ($i = 0; $i < count($images); $i++) {

		$image = $images[$i];

		if (empty($image['image'])) {
			continue;
		}

		$image_id = (int) $image['image'];

		$image_src = wp_get_attachment_image_src($image_id, 'full');
		$image_src = ($image_src && is_array($image_src)) ? $image_src[0] : '';

		$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);

		if (!empty($image_src)) {
			$image_sources[] = array(
				'id'  => $image_id,
				'src' => $image_src,
				'alt' => $image_alt
			);
		}
	}

	if (count($image_sources) > 1) { ?>

		<ul id="post-gallery" class="cS-hidden post-gallery">
			<?php foreach ($image_sources as $img) { ?>
				<li data-thumb="<?php echo esc_attr($img['src']); ?>">
					<?php 
					echo wp_get_attachment_image(
						$img['id'],
						'full',
						false,
						array(
							'alt'   => $img['alt'],
							'sizes' => '100vw'
						)
					);
					?>
				</li>
			<?php } ?>
		</ul>

	<?php } else if (count($image_sources) === 1) {

		$img = $image_sources[0];
		?>

		<ul class="featured-image">
			<li>
				<img src="<?php echo esc_attr($img['src']); ?>" alt="<?php echo esc_attr($img['alt']); ?>" />
			</li>
		</ul>

	<?php }
}