<?php
/**
 * Template Name: Home
 *
 * @package gralbcn
 */

get_header(); ?>
<div class="container grid">

			<div class="container-presentation-home gridRow">

				<div class="home-main-image-mobile"><?php echo get_the_post_thumbnail( get_the_ID(), 'full' ) ?></div>
		
				<div class="two-thirds column">
					<div class="featured-text-home"><?php the_field('featured_text_home'); ?></div>
					<div class="main-text-home"><?php the_field('main_text_home'); ?></div>
				</div>

				<div class="one-third column">
					<div class="home-main-image"><?php echo get_the_post_thumbnail( get_the_ID(), 'full' ) ?></div>
					<?php if( have_rows('education') ): ?>
					<div class="education-block">
						<h6>Education</h6>
						<ul class="education-list">
						<?php while( have_rows('education') ): the_row(); 
							$year = get_sub_field('year_education');
							$title = get_sub_field('education_education');
						?>
							<li>
							<span class="education-year"><?php echo esc_html($year); ?></span>
							<span class="education-title"><?php echo esc_html($title); ?></span>
							</li>
						<?php endwhile; ?>
						</ul>
					</div>
					<?php endif; ?>
				</div>
		
			</div>



			
		<div class="container-images-home twelve columns clearfix">
		
					
				<div class="images-home-block">
						<?php 
						$images = [
							['field' => 'image1_home', 'text' => 'text_image1_home'],
							['field' => 'image2_home', 'text' => 'text_image2_home'],
							['field' => 'image3_home', 'text' => 'text_image3_home']
						];
						
						foreach ($images as $img) :
							$image_url = get_field($img['field']);
							$image_text = get_field($img['text']);
							if ($image_url):
						?>
							<div class="image-item" style="background-image: url('<?php echo esc_url($image_url); ?>');">
							<div class="overlay-images-home"></div>
							<div class="image-text"><?php echo esc_html($image_text); ?></div>
							</div>
						<?php 
							endif;
						endforeach; 
						?>
				</div>

		
		</div>



		<div class="container-last-home gridRow">
		
			


				<div class="latest-news-block">
					<h6>Latest News</h6>
					<div class="news-columns">
						
						<!-- Publications Column -->
						<div class="news-column">
						<h5>—Publications</h5>
						<?php
						$pubs = new WP_Query(array(
							'post_type' => 'post',
							'posts_per_page' => 2,
							'category_name' => 'publications'
						));
						if ($pubs->have_posts()) :
							while ($pubs->have_posts()) : $pubs->the_post();
							$authors = get_field('authors');
							$year = get_field('year'); // Si tienes un campo year; si no, extrae del post_date
							$theme = get_field('theme');
							$edition = get_field('edition');

							echo '<p>';
							echo esc_html($authors) . ' (' . esc_html($year) . '). ';
							echo '<span class="blue">' . get_the_title() . '</span>. ';
							echo esc_html($theme) . ', ' . esc_html($edition);
							echo '</p>';
							endwhile;
							wp_reset_postdata();
						else:
							echo '<p>No publications found.</p>';
						endif;
						?>
						<div class="container-center-button">
							<a href="/publications" class="btn btn-primary">View more</a>
						</div>	
						</div>

						<!-- Presentations Column -->
						<div class="news-column">
						<h5>—Talks</h5>
						<?php
						$pres = new WP_Query(array(
							'post_type' => 'post',
							'posts_per_page' => 2,
							'category_name' => 'presentations'
						));
						if ($pres->have_posts()) :
							while ($pres->have_posts()) : $pres->the_post();
							$authors = get_field('authors');
							$full_date = get_field('full_date'); // picker de fecha
							$year = '';
							if ($full_date) {
								$year = date('Y', strtotime($full_date));
							}
							$extra_info = get_field('extra_info');
							$location = get_field('location');

							echo '<p>';
							echo esc_html($authors) . ' (' . esc_html($year) . '). ';
							echo '<span class="blue">' . get_the_title() . '</span>. ';
							//echo esc_html($extra_info) . '. ';
							echo esc_html($full_date) . ', ' . esc_html($location);
							echo '</p>';
							endwhile;
							wp_reset_postdata();
						else:
							echo '<p>No presentations found.</p>';
						endif;
						?>
						<div class="container-center-button">
							<a href="/presentations" class="btn btn-primary">View more</a>
						</div>
						</div>

					</div>
				</div>

		
		</div> 









</div> <!-- end container -->







<?php get_footer(); ?>