{{template "layout/header.html" .}}
<body>

{{template "layout/nav.html" .}}

<div class="container posts-container">
    <div class="posts-header">
        <h1>社区帖子</h1>
        {{if .IsLoggedIn}}
        <a href="/studio/write" class="btn btn-primary">撰写帖子</a>
        {{end}}
    </div>

    {{if .Error}}
    <div class="error-message">{{.Error}}</div>
    {{end}}

    {{if .Keyword}}
    <div class="search-hint">搜索：<strong>{{.Keyword}}</strong></div>
    {{end}}

    <div class="posts-list">
        {{if eq (len .Posts) 0}}
        <div class="empty-state">暂无帖子</div>
        {{else}}
        {{range .Posts}}
        <article class="post-card">
            <h2 class="post-card-title">
                <a href="/posts/{{.ID}}">{{.Title}}</a>
            </h2>
            <div class="post-card-meta">
                <span class="post-author">{{if .AuthorName}}{{.AuthorName}}{{else}}该用户已注销{{end}}</span>
                <span class="post-time">{{.CreatedAt.Format "2006-01-02 15:04"}}</span>
            </div>
            <p class="post-card-summary">{{if .Excerpt}}{{.Excerpt}}{{else}}{{printf "%.200s" .Body}}{{end}}</p>
        </article>
        {{end}}
        {{end}}
    </div>

    {{if gt .TotalPages 1}}
    <div class="pagination">
        {{if gt .Page 1}}
        <a href="?page={{.PrevPage}}{{if .Keyword}}&keyword={{.Keyword}}{{end}}" class="page-link">上一页</a>
        {{end}}
        <span class="page-info">第 {{.Page}} / {{.TotalPages}} 页 (共 {{.Total}} 条)</span>
        {{if lt .Page .TotalPages}}
        <a href="?page={{.NextPage}}{{if .Keyword}}&keyword={{.Keyword}}{{end}}" class="page-link">下一页</a>
        {{end}}
    </div>
    {{end}}
</div>

{{template "layout/footer.html" .}}

<script src="/static/js/common.js?v={{assetV "/static/js/common.js"}}"></script>
</body>
</html>
