<?php

	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}
	/**
	 * Popular post
	 */
	$popular_posts = get_posts(
		[
			'post_type'           => 'post',
			'posts_per_page'      => 1,
			'meta_key'            => 'is_popular',
			'meta_value'          => '1',
			'ignore_sticky_posts' => true,
		]
	);
	/**
	 * Latest posts
	 */
	$latest_posts = get_posts(
		[
			'post_type'           => 'post',
			'posts_per_page'      => 3,
			'post_status'         => 'publish',
			'ignore_sticky_posts' => true,
			'post__not_in'        => ! empty( $popular_posts )
				? [ $popular_posts[0]->ID ]
				: [],
		]
	);

?>
<section class="g-2b384dbe" data-section-group="dff9c86d0b1" data-section-status="archived">
	<div class="g-fdc4b4e9" id="elem-4ae7494ed825b57d">
		<div class="g-404ca71d" data-component-group="39016585f02" data-bs-locator="7795e00a" data-section-config="492097cef">
			<?php if ( ! empty( $popular_posts ) ) : ?>
				<div
					class="g-26d3f747"
					aria-labelledby="popular-post-title"
				>
					<div class="g-3a4660a7" id="elem-77d680e6725e1a7e">
						<h2
							id="popular-post-title"
							class="g-d4e0af69 g-e073ab23"
							data-mui-unit="7a9489d22d" data-component-priority="low" data-bs-event="pageview" data-bs-expanded="20bc3414e2d" data-test-slide-to="442c7e64b824"
						>
						Popular posts
						</h2>
					</div>
					<div class="g-7033e293 g-3bf98ad4" id="elem-823babf7d9c3b5bb">
						<?php
							$post = $popular_posts[0];
							setup_postdata( $post );
							get_template_part(
								'templates/post-card',
								null,

							);
							wp_reset_postdata();
						?>
					</div>
				</div>
			<?php endif; ?>
			<?php if ( ! empty( $latest_posts ) ) : ?>
				<aside
					class="g-3e0a4756"
					aria-labelledby="latest-posts-title"
				>
					<div class="g-adc0ef96 g-b8646578" data-analytics-interval="c6654fc327" data-analytics-color="warning">
						<h2
							id="latest-posts-title"
							class="g-d4e0af69 g-6d6980ed"
							id="elem-aca96a91ec32c93e"
						>
						Latest posts
						</h2>
					</div>
					<?php
						foreach ( $latest_posts as $key => $post ) :
							setup_postdata( $post );
							?>
							<?php
							if ( $key !== 0 ) {
								echo '<hr class="g-5ceecc1f" />';
							}
							get_template_part(
								'templates/post-card',
								null,
								[
									'size' => 'small',
								]
							);
							?>
						<?php
						endforeach;
						wp_reset_postdata();
					?>
				</aside>
			<?php endif; ?>
		</div>
		<?php
			$posts_page_id = get_option( 'page_for_posts' );

			if ( $posts_page_id ) :
				?>
				<div class="g-9a06d9e1" data-block-action="hover" data-element-variant="filled" data-bs-focus="6c6627">
					<a href="<?php echo esc_url( get_permalink( $posts_page_id ) ); ?>" class="g-c43b1a32" id="elem-04737f93fed55ddd">
						<span>View all</span>
					</a>
				</div>
			<?php endif; ?>
	</div>
</section>