<?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-242b8bd7" data-section-position="center" data-bs-elevation="8291748d7d" data-block-variant="outlined" data-component-target="dde01f6e" data-component-type="button">
	<div class="g-957a8097" id="elem-e547b51a4eded0ec">
		<div class="g-6a8f6bdd" data-analytics-component="1f030161f" data-block-priority="medium" data-analytics-testid="852f7d36a">
			<?php if ( ! empty( $popular_posts ) ) : ?>
				<div
					class="g-b98d44c4"
					aria-labelledby="popular-post-title"
				>
					<div class="g-b5040a3c" id="elem-46b60430a40d26f7">
						<h2
							id="popular-post-title"
							class="g-94fa0424 g-2ec69fc9"
							data-block-trigger="3ede78e396ae" data-test-slide-to="c3f01fa179" data-bs-elevation="18d6bd9fc0f5" data-mui-pause="2c0c17a4828e" data-mui-loading="0e6044454aba"
						>
						Popular posts
						</h2>
					</div>
					<div class="g-b0ad3e14 g-065f1332" id="elem-4d79b9ed9b9bc66e">
						<?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-60071e2a"
					aria-labelledby="latest-posts-title"
				>
					<div class="g-2232b023 g-fac249ac" data-test-locator="02393ab8b21b" data-widget-size="xl" data-component-mode="readonly" data-block-layout="59cebc6">
						<h2
							id="latest-posts-title"
							class="g-94fa0424 g-e9694222"
							id="elem-b60bcb4933428bc8"
						>
						Latest posts
						</h2>
					</div>
					<?php
						foreach ( $latest_posts as $key => $post ) :
							setup_postdata( $post );
							?>
							<?php
							if ( $key !== 0 ) {
								echo '<hr class="g-efea2a21" />';
							}
							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-28529c69" data-section-handler="66b7ee4d2" data-module-variant="filled" data-analytics-qa="2fd0b2" data-element-animation="bounce" data-section-category="commerce">
					<a href="<?php echo esc_url( get_permalink( $posts_page_id ) ); ?>" class="g-52725655" id="elem-8865fc4fae13267c">
						<span>View all</span>
					</a>
				</div>
			<?php endif; ?>
	</div>
</section>