<?php
/**
 * 2026企业CMS - 默认模板文章详情页
 */
$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:30px;">
        <div style="flex:1;">
            <div class="article-detail">
                <h1 class="title"><?php echo xss_clean($article['title']); ?></h1>
                <div class="meta">
                    <span>发布时间：<?php echo date('Y-m-d H:i', strtotime($article['published_at'] ?: $article['created_at'])); ?></span>
                    <span style="margin-left:20px;">作者：<?php echo xss_clean($article['author_name'] ?: '管理员'); ?></span>
                    <span style="margin-left:20px;">浏览量：<?php echo $article['views']; ?></span>
                    <?php if ($article['tags']): ?>
                    <span style="margin-left:20px;">标签：
                        <?php foreach (explode(',', $article['tags']) as $tag): ?>
                        <a href="<?php echo cms_url('search', ['q' => $tag]); ?>" style="margin-right:5px;"><?php echo xss_clean($tag); ?></a>
                        <?php endforeach; ?>
                    </span>
                    <?php endif; ?>
                </div>
                <div class="content">
                    <?php echo $article['content']; ?>
                </div>
            </div>
            
            <!-- 上下篇导航 -->
            <div style="display:flex;justify-content:space-between;margin-top:30px;padding:20px;background:#fff;border-radius:8px;">
                <?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']]);
                ?>
                <div>
                    <?php if ($prev): ?>
                    <a href="<?php echo cms_url('article', ['slug' => $prev['slug']]); ?>">← <?php echo xss_clean(str_cut($prev['title'],20)); ?></a>
                    <?php endif; ?>
                </div>
                <div>
                    <?php if ($next): ?>
                    <a href="<?php echo cms_url('article', ['slug' => $next['slug']]); ?>"><?php echo xss_clean(str_cut($next['title'],20)); ?> →</a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        
        <!-- 侧边栏 -->
        <div class="sidebar">
            <div class="widget">
                <h3 class="widget-title">热门文章</h3>
                <ul style="list-style:none;">
                    <?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 style="padding:8px 0;border-bottom:1px solid #eee;">
                        <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 style="list-style:none;">
                    <?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 style="padding:8px 0;border-bottom:1px solid #eee;">
                        <a href="<?php echo cms_url('product', ['slug' => $rp['slug']]); ?>"><?php echo xss_clean($rp['title']); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
    </div>
</div>
