<?php
/**
 * 2026企业CMS - 文章详情页（优化版）
 * UI Designer: 像素君
 * 设计系统版本: 2.0
 */
$pageDescription = $article['summary'] ?: strip_tags(mb_substr($article['content'],0,200,'UTF-8'));
$pageKeywords = $article['seo_keywords'] ?: $article['tags'];
$breadcrumbItems = [
    ['title' => '新闻资讯', 'url' => cms_url('news')],
    ['title' => $article['title']]
];
?>
<?php echo breadcrumb($breadcrumbItems); ?>

<div class="main-content">
    <div class="container" style="display: flex; gap: var(--space-8);">
        <!-- 主内容区 -->
        <div style="flex: 1;">
            <div class="article-detail">
                <h1 class="title"><?php echo xss_clean($article['title']); ?></h1>
                
                <div class="meta">
                    <span>
                        <svg width="16" height="16" viewBox="0 0 16 16" fill="none" style="margin-right: 4px; vertical-align: middle;">
                            <path d="M8 0C3.58 0 0 3.58 0 8C0 12.42 3.58 16 8 16C12.42 16 16 12.42 16 8C16 3.58 12.42 0 8 0ZM8 14.5C4.96 14.5 2.5 12.04 2.5 8C2.5 4.96 4.96 2.5 8 2.5C11.04 2.5 13.5 4.96 13.5 8C13.5 11.04 11.04 14.5 8 14.5Z" fill="currentColor"/>
                        </svg>
                        <?php echo date('Y-m-d H:i', strtotime($article['published_at'] ?: $article['created_at'])); ?>
                    </span>
                    
                    <span style="margin-left: var(--space-6);">
                        <svg width="16" height="16" viewBox="0 0 16 16" fill="none" style="margin-right: 4px; vertical-align: middle;">
                            <path d="M8 0C3.58 0 0 3.58 0 8C0 12.42 3.58 16 8 16C12.42 16 16 12.42 16 8C16 3.58 12.42 0 8 0ZM8 14.5C4.96 14.5 2.5 12.04 2.5 8C2.5 4.96 4.96 2.5 8 2.5C11.04 2.5 13.5 4.96 13.5 8C13.5 11.04 11.04 14.5 8 14.5Z" fill="currentColor"/>
                        </svg>
                        <?php echo xss_clean($article['author_name'] ?: '管理员'); ?>
                    </span>
                    
                    <span style="margin-left: var(--space-6);">
                        <svg width="16" height="16" viewBox="0 0 16 16" fill="none" style="margin-right: 4px; vertical-align: middle;">
                            <path d="M8 0C3.58 0 0 3.58 0 8C0 12.42 3.58 16 8 16C12.42 16 16 12.42 16 8C16 3.58 12.42 0 8 0ZM11.5 8.75H8.75V11.5H7.25V8.75H4.5V7.25H7.25V4.5H8.75V7.25H11.5V8.75Z" fill="currentColor"/>
                        </svg>
                        浏览量：<?php echo $article['views']; ?>
                    </span>
                    
                    <?php if ($article['tags']): ?>
                        <span style="margin-left: var(--space-6);">
                            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" style="margin-right: 4px; vertical-align: middle;">
                                <path d="M8 0C3.58 0 0 3.58 0 8C0 12.42 3.58 16 8 16C12.42 16 16 12.42 16 8C16 3.58 12.42 0 8 0ZM12.5 8.5L7 14L3.5 10.5L5.25 8.75L7 10.5L10.75 6.75L12.5 8.5Z" fill="currentColor"/>
                            </svg>
                            <?php foreach (explode(',', $article['tags']) as $tag): ?>
                                <a href="<?php echo cms_url('search', ['q' => $tag]); ?>" class="article-tag">
                                    <?php echo xss_clean($tag); ?>
                                </a>
                            <?php endforeach; ?>
                        </span>
                    <?php endif; ?>
                </div>
                
                <div class="content">
                    <?php echo $article['content']; ?>
                </div>
            </div>
            
            <!-- 上下篇导航 -->
            <div class="article-nav">
                <?php 
                $prev = db_query_one("SELECT `id`,`title`,`slug` FROM `articles` WHERE `status`=1 AND `id`<? ORDER BY `id` DESC LIMIT 1", [$article['id']]);
                $next = db_query_one("SELECT `id`,`title`,`slug` FROM `articles` WHERE `status`=1 AND `id`>? ORDER BY `id` ASC LIMIT 1", [$article['id']]);
                ?>
                
                <?php if ($prev): ?>
                    <a href="<?php echo cms_url('article', ['slug' => $prev['slug']]); ?>" class="article-nav-link article-nav-prev">
                        <svg width="20" height="20" viewBox="0 0 20 20" fill="none">
                            <path d="M12 4L6 10L12 16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                        </svg>
                        <div>
                            <div class="article-nav-label">上一篇</div>
                            <div class="article-nav-title"><?php echo xss_clean(str_cut($prev['title'], 20)); ?></div>
                        </div>
                    </a>
                <?php endif; ?>
                
                <?php if ($next): ?>
                    <a href="<?php echo cms_url('article', ['slug' => $next['slug']]); ?>" class="article-nav-link article-nav-next">
                        <div>
                            <div class="article-nav-label">下一篇</div>
                            <div class="article-nav-title"><?php echo xss_clean(str_cut($next['title'], 20)); ?></div>
                        </div>
                        <svg width="20" height="20" viewBox="0 0 20 20" fill="none">
                            <path d="M8 4L14 10L8 16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                        </svg>
                    </a>
                <?php endif; ?>
            </div>
        </div>
        
        <!-- 侧边栏 -->
        <aside class="sidebar">
            <div class="widget">
                <h3 class="widget-title">热门文章</h3>
                <ul class="sidebar-list">
                    <?php $hotArticles = db_query("SELECT `id`,`title`,`slug` FROM `articles` WHERE `status`=1 ORDER BY `views` DESC LIMIT 5"); ?>
                    <?php foreach ($hotArticles as $ha): ?>
                        <li>
                            <a href="<?php echo cms_url('article', ['slug' => $ha['slug']]); ?>">
                                <?php echo xss_clean($ha['title']); ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>
            
            <div class="widget">
                <h3 class="widget-title">推荐产品</h3>
                <ul class="sidebar-list">
                    <?php $recProducts = db_query("SELECT `id`,`title`,`slug` FROM `products` WHERE `status`=1 AND `is_recommend`=1 LIMIT 5"); ?>
                    <?php foreach ($recProducts as $rp): ?>
                        <li>
                            <a href="<?php echo cms_url('product', ['slug' => $rp['slug']]); ?>">
                                <?php echo xss_clean($rp['title']); ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </aside>
    </div>
</div>

<!-- 文章详情页额外样式 -->
<style>
.article-tag {
    display: inline-block;
    padding: 2px 8px;
    background: var(--color-gray-100);
    color: var(--color-gray-600);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    margin-left: var(--space-2);
    transition: all var(--transition-fast);
}

.article-tag:hover {
    background: var(--color-secondary);
    color: white;
}

.article-nav {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    margin-top: var(--space-8);
    padding: var(--space-6);
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.article-nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    color: var(--color-gray-600);
    text-decoration: none;
    padding: var(--space-4);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    flex: 1;
}

.article-nav-link:hover {
    background: var(--color-gray-50);
    color: var(--color-secondary);
}

.article-nav-next {
    justify-content: flex-end;
    text-align: right;
}

.article-nav-label {
    font-size: var(--text-xs);
    color: var(--color-gray-400);
    margin-bottom: var(--space-1);
}

.article-nav-title {
    font-size: var(--text-sm);
    font-weight: 500;
}

.sidebar-list {
    list-style: none;
}

.sidebar-list li {
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-gray-100);
}

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

.sidebar-list li a {
    color: var(--color-gray-600);
    font-size: var(--text-sm);
    transition: all var(--transition-fast);
    display: block;
}

.sidebar-list li a:hover {
    color: var(--color-secondary);
    padding-left: var(--space-2);
}

@media (max-width: 1024px) {
    .container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .article-nav {
        flex-direction: column;
    }
}
</style>
