<?php
/**
 * 2026企业CMS - 默认模板搜索结果页
 */
$pageDescription = '搜索结果 - ' . SITE_NAME;
$breadcrumbItems = [['title' => '搜索结果']];
?>
<?php echo breadcrumb($breadcrumbItems); ?>

<div class="main-content">
    <div class="container" style="display:flex;gap:30px;">
        <div style="flex:1;">
            <h2 style="font-size:24px;margin-bottom:20px;color:#333;">
                搜索结果：<span style="color:#2c82e0;"><?php echo xss_clean($keyword); ?></span>
            </h2>
            
            <?php if (!$keyword): ?>
            <div style="text-align:center;padding:60px;color:#999;">请输入搜索关键词</div>
            <?php elseif (empty($results['articles']) && empty($results['products'])): ?>
            <div style="text-align:center;padding:60px;color:#999;">
                <p style="font-size:18px;margin-bottom:10px;">没有找到相关内容</p>
                <p>请尝试其他关键词搜索</p>
            </div>
            <?php else: ?>
            
            <!-- 文章结果 -->
            <?php if (!empty($results['articles'])): ?>
            <div style="margin-bottom:30px;">
                <h3 style="font-size:18px;color:#333;margin-bottom:15px;padding-bottom:10px;border-bottom:2px solid #2c82e0;">文章 (<?php echo count($results['articles']); ?>)</h3>
                <?php foreach ($results['articles'] as $r): ?>
                <div style="padding:15px;background:#fff;margin-bottom:10px;border-radius:4px;border-left:3px solid #2c82e0;">
                    <a href="<?php echo cms_url('article', ['slug' => $r['slug']]); ?>" style="font-size:16px;color:#333;display:block;margin-bottom:5px;"><?php echo xss_clean($r['title']); ?></a>
                    <p style="color:#666;font-size:13px;margin:0;"><?php echo xss_clean(str_cut($r['summary'],100)); ?></p>
                </div>
                <?php endforeach; ?>
            </div>
            <?php endif; ?>
            
            <!-- 产品结果 -->
            <?php if (!empty($results['products'])): ?>
            <div>
                <h3 style="font-size:18px;color:#333;margin-bottom:15px;padding-bottom:10px;border-bottom:2px solid #2c82e0;">产品 (<?php echo count($results['products']); ?>)</h3>
                <div class="grid" style="grid-template-columns:repeat(2,1fr);">
                    <?php foreach ($results['products'] as $r): ?>
                    <div class="card">
                        <a href="<?php echo cms_url('product', ['slug' => $r['slug']]); ?>" style="display:flex;align-items:center;gap:15px;padding:15px;">
                            <div style="flex:1;">
                                <div style="font-size:15px;color:#333;margin-bottom:5px;"><?php echo xss_clean($r['title']); ?></div>
                                <div style="color:#666;font-size:13px;"><?php echo xss_clean(str_cut($r['summary'],60)); ?></div>
                            </div>
                        </a>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
            <?php endif; ?>
            
            <?php endif; ?>
        </div>
        
        <!-- 侧边栏 -->
        <div class="sidebar">
            <div class="widget">
                <h3 class="widget-title">热门搜索</h3>
                <div style="display:flex;flex-wrap:wrap;gap:8px;">
                    <?php $hotKeywords = ['企业网站','SEO优化','微信小程序','网络推广','CMS系统']; ?>
                    <?php foreach ($hotKeywords as $hk): ?>
                    <a href="<?php echo cms_url('search', ['q' => urlencode($hk)]); ?>" style="padding:5px 12px;background:#f5f5f5;border-radius:20px;color:#666;font-size:13px;"><?php echo $hk; ?></a>
                    <?php endforeach; ?>
                </div>
            </div>
            
            <div class="widget">
                <h3 class="widget-title">最新文章</h3>
                <ul style="list-style:none;">
                    <?php $latest = db_query("SELECT `title`,`slug` FROM `articles` WHERE `status`=1 ORDER BY `id` DESC LIMIT 5"); ?>
                    <?php foreach ($latest as $l): ?>
                    <li style="padding:8px 0;border-bottom:1px solid #eee;">
                        <a href="<?php echo cms_url('article', ['slug' => $l['slug']]); ?>"><?php echo xss_clean($l['title']); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
    </div>
</div>
