<?php
/**
 * 2026企业CMS - 分类文章列表模板
 */
?>
<!-- 面包屑导航 -->
<?php echo category_breadcrumb($category['id']); ?>

<!-- 分类标题 -->
<section class="category-header">
    <div class="container">
        <h1><?php echo htmlspecialchars($category['name']); ?></h1>
        <?php if ($category['description']): ?>
            <p class="category-description"><?php echo htmlspecialchars($category['description']); ?></p>
        <?php endif; ?>
        <p class="category-count">共 <?php echo $total; ?> 篇文章</p>
    </div>
</section>

<!-- 文章列表 -->
<section class="category-articles">
    <div class="container">
        <?php if (empty($articles)): ?>
            <div class="empty-state">
                <p>该分类下暂无文章</p>
            </div>
        <?php else: ?>
            <div class="article-list">
                <?php foreach ($articles as $article): ?>
                    <div class="article-item">
                        <?php if ($article['cover_image']): ?>
                            <div class="article-cover">
                                <a href="<?php echo cms_url('article', ['slug' => $article['slug']]); ?>">
                                    <img src="<?php echo $article['cover_image']; ?>" alt="<?php echo htmlspecialchars($article['title']); ?>">
                                </a>
                            </div>
                        <?php endif; ?>
                        
                        <div class="article-info">
                            <h2 class="article-title">
                                <a href="<?php echo cms_url('article', ['slug' => $article['slug']]); ?>">
                                    <?php echo htmlspecialchars($article['title']); ?>
                                </a>
                            </h2>
                            
                            <div class="article-meta">
                                <span class="meta-date">
                                    <i class="fas fa-calendar"></i>
                                    <?php echo date('Y-m-d', strtotime($article['published_at'] ?? $article['created_at'])); ?>
                                </span>
                                <span class="meta-views">
                                    <i class="fas fa-eye"></i>
                                    <?php echo $article['views']; ?> 浏览
                                </span>
                            </div>
                            
                            <?php if ($article['summary']): ?>
                                <div class="article-summary">
                                    <?php echo htmlspecialchars($article['summary']); ?>
                                </div>
                            <?php endif; ?>
                            
                            <div class="article-read-more">
                                <a href="<?php echo cms_url('article', ['slug' => $article['slug']]); ?>" class="btn btn-primary">阅读全文</a>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
            
            <!-- 分页 -->
            <?php if ($totalPage > 1): ?>
                <div class="pagination-wrapper">
                    <?php
                    $urlPattern = '/index.php?p=category&slug=' . $category['slug'] . '&page=%d';
                    echo paginate($total, $page, $pageSize, $urlPattern);
                    ?>
                </div>
            <?php endif; ?>
        <?php endif; ?>
    </div>
</section>

<!-- 分类侧边栏（可选） -->
<aside class="category-sidebar">
    <div class="container">
        <div class="sidebar-widget">
            <h3>子分类</h3>
            <?php
            $subcategories = db_query("SELECT * FROM `categories` WHERE `parent_id`=? AND `status`=1 ORDER BY `sort_order` ASC", [$category['id']]);
            if ($subcategories):
            ?>
                <ul class="subcategory-list">
                    <?php foreach ($subcategories as $subcat): ?>
                        <li>
                            <a href="<?php echo cms_url('category', ['slug' => $subcat['slug']]); ?>">
                                <?php echo htmlspecialchars($subcat['name']); ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            <?php else: ?>
                <p>暂无子分类</p>
            <?php endif; ?>
        </div>
    </div>
</aside>

<style>
.category-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 60px 0;
    text-align: center;
}

.category-header h1 {
    font-size: 36px;
    margin-bottom: 10px;
}

.category-description {
    font-size: 16px;
    opacity: 0.9;
    margin-bottom: 10px;
}

.category-count {
    font-size: 14px;
    opacity: 0.8;
}

.category-articles {
    padding: 60px 0;
}

.article-list {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.article-item {
    display: flex;
    gap: 30px;
    padding: 30px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: transform 0.3s;
}

.article-item:hover {
    transform: translateY(-5px);
}

.article-cover {
    flex: 0 0 300px;
    height: 200px;
    overflow: hidden;
    border-radius: 8px;
}

.article-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.article-item:hover .article-cover img {
    transform: scale(1.05);
}

.article-info {
    flex: 1;
}

.article-title {
    font-size: 24px;
    margin-bottom: 10px;
}

.article-title a {
    color: #333;
    text-decoration: none;
    transition: color 0.3s;
}

.article-title a:hover {
    color: #667eea;
}

.article-meta {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    color: #666;
    font-size: 14px;
}

.article-summary {
    color: #666;
    line-height: 1.8;
    margin-bottom: 15px;
}

.article-read-more .btn {
    padding: 8px 20px;
    font-size: 14px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.pagination-wrapper {
    margin-top: 40px;
    display: flex;
    justify-content: center;
}

.category-sidebar {
    padding: 40px 0;
    background: #f8f9fa;
}

.sidebar-widget {
    background: white;
    padding: 20px;
    border-radius: 8px;
}

.sidebar-widget h3 {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #667eea;
}

.subcategory-list {
    list-style: none;
    padding: 0;
}

.subcategory-list li {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.subcategory-list li:last-child {
    border-bottom: none;
}

.subcategory-list li a {
    color: #333;
    text-decoration: none;
    transition: color 0.3s;
}

.subcategory-list li a:hover {
    color: #667eea;
}

@media (max-width: 768px) {
    .article-item {
        flex-direction: column;
    }
    
    .article-cover {
        flex: none;
        height: 200px;
    }
}
</style>
