<?php
/**
 * Generated by blog pipeline.
 */
get_header();
?>
<?php
	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	$page_id = get_queried_object_id();

	$short_description = get_post_meta(
		$page_id,
		'short_description',
		true
	);
?>
<header class="g-f19e28d8" data-mui-color="success" data-test-ride="fc7429ee">
	<div class="g-b24e2866" id="elem-fa37752c54ce8893">
		<div class="g-b1e07ee6" data-bs-action="toggle" data-module-theme="auto">
			<?php if ( has_post_thumbnail( $page_id ) ) : ?>
				<div class="g-b556a378" id="elem-6731d4e9ddb159e0">
					<figure class="g-5f39b6ee g-5bbf1cf1">
						<?php
							echo get_the_post_thumbnail(
								$page_id,
								'',
								[
									'loading' => 'eager',
								]
							);
						?>
					</figure>
				</div>
			<?php endif; ?>
			<div class="g-9f8562d8" data-component-layout="92d479c" data-test-target="d67a74ea137" data-bs-focus="936c8de964a4" data-bs-target="bd3f84" data-section-state="error">
				<h1 class="g-924d7f52 g-5e158376" id="elem-7f54d31784b6f36d">
					<?php echo esc_html( get_bloginfo( 'name' ) ); ?>
				</h1>
				<?php if ( ! empty( $short_description ) ) : ?>
					<div class="g-7458bb91 g-69390e68" data-bs-cy="fce464fff" data-module-target="b9b481800a4a" data-test-size="xl" data-component-size="small" data-test-selected="0f2673278">
						<?php echo esc_html( $short_description ); ?>
					</div>
				<?php endif; ?>
				<div class="g-ec88d17e" id="elem-20e99849ac7beadb">
					<?php get_template_part( 'templates/searchform' ); ?>
				</div>
			</div>
		</div>
	</div>
</header>

<section class="g-4a9cbb8e g-8b3ced75" data-module-action="toggle" data-widget-animation="slide" data-widget-category="engagement">
    <div class="g-b24e2866" id="elem-85d693d5bce2aad2">
        <div class="g-351cf66e" data-analytics-dismiss="1e0db63" data-component-role="sidebar">
            <h2 class="g-5e158376 g-b8f0b039" id="elem-4003b4e08a8dc1f8">Your Central Hub for Sports Coverage</h2>
            <p class="g-aea53723 g-b8f0b039 g-a7fcd570" data-mui-fixture="5aba1f8ad141" data-element-content="7ef0ec3f5" data-element-mode="view" data-test-label="27fa098">Welcome to Prime Athletics, your dedicated platform for comprehensive sports coverage. We provide up-to-date news, match results, and expert analysis across all major leagues. Our team curates information from trusted sources to keep you informed. Whether you follow football, basketball, baseball, or hockey, our hub offers structured insights into games, player performances, and league standings. Explore our content to stay connected with the world of sports.</p>
        </div>
    </div>
</section>

<section class="g-d2fc17f8" data-mui-metric="548530c0" data-component-trigger="170cc08" data-mui-track="399f5283d6be" data-mui-toggle="modal" data-test-selector="351f5d09444">
    <div class="g-b24e2866" id="elem-b15cd5725bfe30be">
        <h2 class="g-5e158376 g-3acb753b" data-bs-expanded="dd4a6cc" data-block-priority="critical" data-module-size="xl">All categories</h2>
        <div class="g-773248dc" id="elem-2e5f1489b0ea4195">
            <?php
                $categories = get_categories(
                    [
                        'orderby'    => 'count',
                        'order'      => 'DESC',
                        'hide_empty' => true,
                    ]
                );

                if ( $categories ) :
                    ?>
                    <?php foreach ( $categories as $category ) : ?>
                    <?php $icon = get_term_meta( $category->term_id, 'icon', true ); ?>
                    <a
                        href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>"
                        class="g-b45ba9c8"
                    >
                        <span class="g-9616ceb6 g-bf1581e5">
                            <?php echo esc_html( $category->name ); ?>
                        </span>
                        <?php if ( ! empty( $icon ) ) : ?>
                            <span class="g-bf84f580">
                                <?php echo esc_html( $icon ); ?>
                            </span>
                        <?php endif; ?>
                    </a>
                <?php endforeach; ?>
                <?php endif; ?>
        </div>
    </div>
</section>

<?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-a741d0e5" data-analytics-goal="9a1924" data-element-theme="auto" data-component-trigger="4c3558b74d9" data-test-automation="634a7e" data-module-state="success">
	<div class="g-b24e2866" id="elem-3384229c3ff6149b">
		<div class="g-9194b937" data-block-action="expand" data-block-status="published" data-widget-handler="0a9809" data-section-position="center">
			<?php if ( ! empty( $popular_posts ) ) : ?>
				<div
					class="g-77802908"
					aria-labelledby="popular-post-title"
				>
					<div class="g-711628e3" id="elem-3ed86f661afd2ac7">
						<h2
							id="popular-post-title"
							class="g-0c2407db g-5e158376"
							data-mui-action="hover" data-test-wrap="dee574" data-block-state="error" data-component-position="top"
						>
						Popular posts
						</h2>
					</div>
					<div class="g-61611ba6 g-a7fcd570" id="elem-cf111553a34cb6e8">
						<?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-17e59ac9"
					aria-labelledby="latest-posts-title"
				>
					<div class="g-071bbc7c g-c43ecf6f" data-section-category="engagement" data-element-target="7aa184b2fb1" data-element-type="primary" data-module-category="content" data-bs-size="small">
						<h2
							id="latest-posts-title"
							class="g-0c2407db g-278f1f3e"
							id="elem-8f121488a47801e9"
						>
						Latest posts
						</h2>
					</div>
					<?php
						foreach ( $latest_posts as $key => $post ) :
							setup_postdata( $post );
							?>
							<?php
							if ( $key !== 0 ) {
								echo '<hr class="g-6a34ca4c" />';
							}
							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-83547a1e" data-block-variant="contained" data-mui-metric="a8a5531a6" data-mui-label="e1674692cbd0" data-test-cy="8ff9299fc7">
					<a href="<?php echo esc_url( get_permalink( $posts_page_id ) ); ?>" class="g-e5f3f08c" id="elem-b198345aa39cc688">
						<span>View all</span>
					</a>
				</div>
			<?php endif; ?>
	</div>
</section>

<?php
	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	$render_page_content = static function ( string $content ): void {
		if ( $content === '' ) {
			return;
		}
		?>
		<div class="g-b24e2866">
			<article id="post-<?php the_ID(); ?>" class="content-wrapper g-81ecbe36">
				<?php echo apply_filters( 'the_content', $content ); ?>
			</article>
		</div>
		<?php
	};

	if ( in_the_loop() ) {
		$render_page_content( get_the_content() );
	} elseif ( have_posts() ) {
		while ( have_posts() ) {
			the_post();
			$render_page_content( get_the_content() );
		}
	}
?>
<?php get_footer(); ?>
