{include file="header.tpl"}

<h1 class="mb-4">搜索: {$keyword}</h1>
<p class="text-muted mb-4">找到 {$pagination.total} 条结果</p>

{if $posts}
<div class="post-list">
{foreach $posts as $post}
<article class="post-card">
<h2 class="post-title">
<a href="{build_url mod='post' id=$post.id}">{$post.title nofilter}</a>
</h2>
<div class="post-meta">
<span><i class="fas fa-user me-1"></i>{$post.author}</span>
<span><i class="fas fa-folder me-1"></i>{$post.category}</span>
<span><i class="fas fa-calendar me-1"></i>{$post.create_time|date_format:'Y-m-d H:i'}</span>
<span><i class="fas fa-eye me-1"></i>{$post.views} 阅读</span>
</div>
<div class="post-content">
{$post.content|truncate:200}
</div>
</article>
{/foreach}
</div>

{if $pagination.total_pages > 1}
<nav class="pagination">
{if $pagination.has_prev}
<a href="{build_url mod='search' keyword=$keyword page=$pagination.page_prev}" class="page-link">上一页</a>
{/if}

{foreach $pagination.display_pages as $p}
{if $p == $pagination.page}
<span class="page-link page-current">{$p}</span>
{else}
<a href="{build_url mod='search' keyword=$keyword page=$p}" class="page-link">{$p}</a>
{/if}
{/foreach}

{if $pagination.has_next}
<a href="{build_url mod='search' keyword=$keyword page=$pagination.page_next}" class="page-link">下一页</a>
{/if}
</nav>
{/if}
{else}
<div class="text-center py-5">
<i class="fas fa-search fa-3x text-muted mb-3"></i>
<p class="text-muted">没有找到相关文章</p>
<a href="{build_url mod='index'}" class="btn btn-primary">返回首页</a>
</div>
{/if}

{include file="footer.tpl"}