<?php
/**
 * CloudForge Theme - Search Results
 */
$pageDescription = '搜索结果 - ' . SITE_NAME;
$breadcrumbItems = [['title' => '搜索结果']];
?>
<?php echo breadcrumb($breadcrumbItems); ?>

<div class="main-content">
    <div class="container container--sidebar">
        <div class="content-main">
            <div class="section-header">
                <span class="section-label">// SEARCH</span>
                <h2 class="section-title">
                    搜索: <span class="search-keyword"><?php echo xss_clean($keyword); ?></span>
                </h2>
            </div>

            <?php if (!$keyword): ?>
            <div class="empty-state">
                <svg width="48" height="48" viewBox="0 0 48 48" fill="none" opacity="0.3"><circle cx="20" cy="20" r="12" stroke="currentColor" stroke-width="1.5"/><path d="M29 29l8 8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
                <p>请输入搜索关键词</p>
            </div>
            <?php elseif (empty($results['articles']) && empty($results['products'])): ?>
            <div class="empty-state">
                <svg width="48" height="48" viewBox="0 0 48 48" fill="none" opacity="0.3"><circle cx="20" cy="20" r="12" stroke="currentColor" stroke-width="1.5"/><path d="M29 29l8 8M20 14v12M14 20h12" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
                <p>没有找到相关内容</p>
                <span>请尝试其他关键词搜索</span>
            </div>
            <?php else: ?>

            <?php if (!empty($results['articles'])): ?>
            <div class="search-group">
                <h3 class="search-group-title">
                    文章
                    <span class="search-group-count"><?php echo count($results['articles']); ?></span>
                </h3>
                <div class="search-result-list">
                    <?php foreach ($results['articles'] as $r): ?>
                    <a href="<?php echo cms_url('article', ['slug' => $r['slug']]); ?>" class="search-result-item">
                        <div class="search-result-body">
                            <h4 class="search-result-title"><?php echo xss_clean($r['title']); ?></h4>
                            <p class="search-result-desc"><?php echo xss_clean(str_cut($r['summary'], 120)); ?></p>
                        </div>
                        <svg class="search-result-arrow" width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M3 8h10M9 4l4 4-4 4" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>
                    </a>
                    <?php endforeach; ?>
                </div>
            </div>
            <?php endif; ?>

            <?php if (!empty($results['products'])): ?>
            <div class="search-group">
                <h3 class="search-group-title">
                    产品
                    <span class="search-group-count"><?php echo count($results['products']); ?></span>
                </h3>
                <div class="product-grid">
                    <?php foreach ($results['products'] as $r): ?>
                    <article class="product-card">
                        <a href="<?php echo cms_url('product', ['slug' => $r['slug']]); ?>" class="product-card-link">
                            <div class="product-card-body">
                                <h3 class="product-card-title"><?php echo xss_clean($r['title']); ?></h3>
                                <p class="product-card-desc"><?php echo xss_clean(str_cut($r['summary'], 60)); ?></p>
                            </div>
                        </a>
                    </article>
                    <?php endforeach; ?>
                </div>
            </div>
            <?php endif; ?>

            <?php endif; ?>
        </div>

        <aside class="sidebar">
            <div class="widget">
                <h3 class="widget-title">// 热门搜索</h3>
                <div class="tag-cloud">
                    <?php $hotKeywords = ['企业网站', 'SEO优化', '微信小程序', '网络推广', 'CMS系统']; ?>
                    <?php foreach ($hotKeywords as $hk): ?>
                    <a href="<?php echo cms_url('search', ['q' => urlencode($hk)]); ?>" class="tag"><?php echo $hk; ?></a>
                    <?php endforeach; ?>
                </div>
            </div>
            <div class="widget">
                <h3 class="widget-title">// 最新文章</h3>
                <ul class="widget-list">
                    <?php $latest = db_query("SELECT `title`,`slug` FROM `articles` WHERE `status`=1 ORDER BY `id` DESC LIMIT 5"); ?>
                    <?php foreach ($latest as $l): ?>
                    <li><a href="<?php echo cms_url('article', ['slug' => $l['slug']]); ?>"><?php echo xss_clean($l['title']); ?></a></li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </aside>
    </div>
</div>
