<?php

// Force Full-Width Layout
add_filter('genesis_pre_get_option_site_layout', '__genesis_return_full_width_content');
remove_action('genesis_loop', 'genesis_do_loop');
add_action('genesis_after_header', 'place_page_intro_section');
add_action('genesis_after_header', 'place_page_highlight_section');
add_action('genesis_after_header', 'places_slider_images');
add_action('genesis_after_header', 'related_place_section');


function place_page_intro_section() {
	$places_intro = get_field('intro');
	if( $places_intro ): 
	$intro_title=$places_intro['title'];
	$place_intro_img=$places_intro['imagevideo']['image']['url'];
	$place_intro_video=$places_intro['imagevideo']['video']['url'];?>
	<section class="places-intro-section">
		<?php if($place_intro_video){?>
			<div class="bg-video">
				<video class="places-video" autoplay muted loop playsinline>
				  <source src="<?php echo $place_intro_video; ?>" type="video/mp4">
				</video>
			</div>
		<?php } else{ ?>
			<div class="bg-image">
				<img class="places-image" src="<?php echo $place_intro_img; ?>"/>
			</div>
		<?php } ?>
		
		<div class="places-intro-content-section">
			<h1><?php echo $intro_title; ?></h1>
		</div>
	</section>
<?php endif; 	
}
function place_page_highlight_section() {
	$places_highlights = get_field('highlights');
	if( $places_highlights ): 
		$highlights_title=$places_highlights['title'];
		$highlights_text=$places_highlights['text'];
		?>
		<div class="places-highlights-section">
			<div class="places-highlights-section-wrapper">
				<h2 class="highlights-section-title"><?php echo $highlights_title; ?></h2>
			</div>
			<div class="places-highlights-content-wrapper">
				<div class="places-highlights-content-left"><?php
					if ( $places_highlights && isset($places_highlights['highlights_repeater']) && is_array($places_highlights['highlights_repeater'])) {
						echo '<ul>';
						foreach( $places_highlights['highlights_repeater'] as $row ) {
							echo '<li>' . $row['repeater_text'] . '</li>';
						}
						echo '</ul>';
					} ?>
				</div>
				<div class="places-highlights-content-right">
					<?php echo $highlights_text;?>
				</div>
			</div>
		</div>
	<?php endif;	
}
function places_slider_images() {
    $images = get_field('image_slider');
	if( $images ): ?>
		<div class="places-page-slider-images">
			<div class="places-gallery-slider">
				<?php foreach( $images as $image ): ?>
					<div>
						<img src="<?php echo esc_url($image['sizes']['large']); ?>" alt="<?php echo esc_attr($image['alt']); ?>"/>
					</div>
				<?php endforeach; ?>
			</div>
		</div>
	<?php endif;
}
function related_place_section() {
	$related_places = get_field('related_places');

if ( $related_places ) {?>
	
	<section class="related_place_slider">
	    <h2><?php echo $related_places['title']?></h2>
	    <div class="related-place-wrapper">
	    <?php	
		echo '<ul class="related-places">';
		foreach ( $related_places['related_slider'] as $related_post ) :
			$post_id   = $related_post->ID;
			$title     = get_the_title($post_id);
			$url       = get_permalink($post_id);
			$related_title_group  = get_field('intro',$post_id);
			$related_title   = isset($related_title_group['title'])? $related_title_group['title'] : '';
			$thumbnail = get_the_post_thumbnail_url( $post_id, 'full' );
			echo '<li class="place-item">';
			if ( $thumbnail ) {
				echo '<a href="' . esc_url($url) . '">';
				echo '<img src="' . esc_url($thumbnail) . '" alt="' . esc_attr($title) . '"/>';
				echo '<div class="overlay"></div>';
				echo '</a>';
			}
			echo '<h4><a href="' . esc_url($url) . '">' . $related_title . '</a></h4>';
			echo '</li>';
		endforeach;
		echo '</ul>';
		echo '</div>';
		echo '</section>';
	}

	
}
genesis();