<?php
/**
 * Template Name: Default
 * 博客归档页 — 默认布局。
 *
 * 变量作用域（由 layout 文件注入）：
 * @var PufferGo_Blog_Archive_Data $data 归档页数据对象。
 *
 * @package PufferGo
 */

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

<main class="puffergo-fullpage-layout">
	<?php if ( ! $data->is_category_page ) : ?>
		<?php puffergo_render_component( 'blog-hero', array( 'data' => $data ) ); ?>
	<?php else : ?>
		<!-- 分类页面包屑 + 标题 -->
		<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8 py-8 sm:py-12">
			<?php puffergo_render_component( 'breadcrumb', array( 'items' => $data->get_breadcrumb_items() ) ); ?>
			<div class="blog-category-header">
				<div class="blog-category-header-inner">
					<h1 class="blog-category-title"><?php echo esc_html( $data->page_title ); ?></h1>
					<?php if ( $data->page_description ) : ?>
						<p class="blog-category-desc"><?php echo esc_html( $data->page_description ); ?></p>
					<?php endif; ?>
				</div>
			</div>
		</div>
	<?php endif; ?>

	<!-- 搜索区域（仅归档页显示） -->
	<?php if ( ! $data->is_category_page ) : ?>
		<div class="search-section">
			<div class="search-wrapper">
				<form class="search-box" method="get" action="<?php echo esc_url( $data->current_url ); ?>">
					<input type="text" name="s" placeholder="<?php esc_attr_e( 'Search keywords...', 'puffergo' ); ?>" class="search-input" value="<?php echo esc_attr( $data->search_query ); ?>" />
					<button class="search-button" type="submit">
						<svg width="20" height="20" viewBox="0 0 20 20" fill="none"><circle cx="9" cy="9" r="8" stroke="currentColor" stroke-width="2" fill="none"/><path d="M15 15L19 19" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
					</button>
				</form>
			</div>
		</div>
	<?php endif; ?>

	<!-- 文章列表 -->
	<div class="blog-article-list">
		<?php if ( ! empty( $data->posts ) ) : ?>
			<div class="articles-grid">
				<?php foreach ( $data->posts as $post_item ) :
					$post_data = $post_item;
					puffergo_render_component( 'blog-article-card', array( 'post_data' => $post_data ) );
				endforeach; ?>
			</div>
		<?php else : ?>
			<div class="no-posts">
				<p><?php esc_html_e( 'No posts found', 'puffergo' ); ?></p>
			</div>
		<?php endif; ?>
	</div>

	<!-- 分页 -->
	<?php
	puffergo_render_component( 'blog-pagination', array(
		'current_page' => $data->paged,
		'max_pages'    => $data->max_pages,
		'current_url'  => $data->pagination_base_url ?: $data->current_url,
	) );
	?>
</main>
