<?php
/**
 * 官网首页
 *
 * 全部文案/配置从数据库读,不再硬编码
 */
require_once dirname(__DIR__) . '/config/config.php';

$pageTitle = '盛木凡 SENMUFAN - 母婴可用抽取式面巾纸 · 柔初舒润系列';
$pageKeywords = '盛木凡,SENMUFAN,母婴抽纸,面巾纸,抽取式纸巾,柔初舒润,原生木浆纸巾,GB/T20808,GB15979,母婴可用抽纸,4层加厚,420张';
$pageDesc = '盛木凡(SENMUFAN)母婴可用抽取式面巾纸,100%原生木浆·4层加厚·420张/包,通过GB/T 20808国家标准、GB 15979卫生标准,柔初舒润系列,呵护宝宝娇嫩肌肤。';

// 主体产品 schema (仍用旗舰产品)
$product = [
    'name'        => '盛木凡 柔初舒润系列 母婴可用抽取式面巾纸',
    'image'       => cfg('site_domain', 'https://www.shengmufan.cn') . '/uploads/images/product-main.png',
    'description' => '100%原生木浆,4层加厚,420张/包,通过GB/T 20808+GB 15979双国标',
    'sku'         => 'SMF-0694',
    'gtin'        => '6977070180694',
];
$extraSchema = [
    ContentHelper::productSchema($product),
];

// 内容数据
$articles = db()->all("SELECT * FROM tbs_content WHERE status = 1 AND type IN ('knowledge','news') ORDER BY is_featured DESC, published_at DESC LIMIT 6");
$faqs = db()->all("SELECT * FROM tbs_content WHERE status = 1 AND type = 'faq' ORDER BY sort_order ASC, id ASC LIMIT 6");
$products = db()->all("SELECT * FROM tbs_content WHERE status = 1 AND type = 'knowledge' AND category = '产品' ORDER BY sort_order ASC, id ASC LIMIT 3");
$features = db()->all("SELECT * FROM tbs_feature WHERE status = 1 ORDER BY sort_order ASC, id ASC");

// v1.3.1: 滚动通知栏数据 (最新发布的内容)
$noticeCount = (int)cfg('notice_count', '5');
$notices = db()->all("SELECT id, slug, title, type, category, published_at, created_at FROM tbs_content WHERE status = 1 ORDER BY is_featured DESC, COALESCE(published_at, created_at) DESC LIMIT ?", [$noticeCount]);

// 信任条 5 个徽章 (| 分隔)
$trustBadges = array_filter(array_map('trim', explode('|', (string)cfg('trust_badges', ''))));

// Hero 浮窗小卡 (每条 "副标题|主标题" 用 | 分隔)
function hero_pill($key) {
    $v = cfg($key, '');
    if (!$v || strpos($v, '|') === false) return ['sub' => '', 'main' => $v];
    $parts = explode('|', $v, 2);
    return ['sub' => trim($parts[0] ?? ''), 'main' => trim($parts[1] ?? '')];
}
$heroPillTL = hero_pill('hero_pill_tl');
$heroPillBL = hero_pill('hero_pill_bl');
$heroPillBR = hero_pill('hero_pill_br');

require __DIR__ . '/header.php';
?>

<!-- v1.3.1: 滚动通知栏 -->
<?php if (!empty($notices)): ?>
<div class="notice-bar">
    <div class="container notice-inner">
        <span class="notice-title"><?= e(cfg('notice_title', '📢 最新动态')) ?></span>
        <div class="notice-track">
            <div class="notice-list" id="noticeList">
                <?php foreach ($notices as $n): ?>
                    <a href="/content.php?slug=<?= e($n['slug'] ?? '') ?>" class="notice-item">
                        <span class="notice-type"><?= e($n['type']) ?></span>
                        <span class="notice-text"><?= e($n['title']) ?></span>
                        <span class="notice-date"><?= e(date('m-d', strtotime($n['published_at'] ?? $n['created_at']))) ?></span>
                    </a>
                <?php endforeach; ?>
            </div>
        </div>
        <a href="/news.php" class="notice-more">更多 →</a>
    </div>
</div>
<?php endif; ?>

<!-- HERO -->
<section class="hero">
    <div class="container hero-inner">
        <div>
            <span class="hero-tag">✦ <?= e(cfg('hero_eyebrow', '盛木凡 · 柔初舒润系列 · 2026 新品')) ?></span>
            <h1>
                <?= e(cfg('hero_title_1', '柔初舒润')) ?><br>
                <span class="green"><?= e(cfg('hero_title_2', '宝宝也能安心用')) ?></span>
            </h1>
            <p class="hero-desc">
                <strong><?= e(cfg('hero_desc_1', '100% 原生木浆 · 4 层加厚 · 单包 420 张')) ?></strong><br>
                <?= e(cfg('hero_desc_2', '通过 GB/T 20808 国家标准、GB 15979 卫生标准。')) ?>
            </p>
            <div class="hero-actions">
                <a class="btn btn-primary btn-lg" href="<?= e(cfg('hero_btn1_url', '/products.php')) ?>"><?= e(cfg('hero_btn1_text', '立即购买')) ?> →</a>
                <a class="btn btn-outline btn-lg" href="<?= e(cfg('hero_btn2_url', '/page.php?slug=brand-story')) ?>"><?= e(cfg('hero_btn2_text', '了解盛木凡')) ?></a>
            </div>
            <?php
            // Hero 下方 4 个徽章 - 从 tbs_site_config.hero_inline_badges 读 (| 分隔)
            $inlineBadges = array_filter(array_map('trim', explode('|', (string)cfg('hero_inline_badges', '✓ GB/T 20808|✓ GB 15979|✓ 100% 原生木浆|✓ 母婴可用'))));
            $badgeIcons   = ['bi-shield-check', 'bi-droplet-half', 'bi-tree', 'bi-heart-pulse', 'bi-award', 'bi-stars'];
            $bi = 0;
            foreach ($inlineBadges as $b): $ic = $badgeIcons[$bi % count($badgeIcons)]; $bi++;
            ?>
            <span><i class="bi <?= e($ic) ?>" style="color:var(--primary)"></i> <?= e($b) ?></span>
            <?php endforeach; ?>
        </div>
        <div class="hero-image">
            <?php if (cfg('img_hero_main')): ?>
                <img src="<?= e(cfg('img_hero_main')) ?>" alt="盛木凡 柔初舒润" style="width:100%;height:100%;object-fit:cover">
            <?php else: ?>
                <div style="font-size:140px;line-height:1">🧻</div>
            <?php endif; ?>
            <div class="hero-feature-pill tl">
                <span class="dot"></span>
                <div>
                    <div style="font-size:11px;color:#6b7280"><?= e($heroPillTL['sub']) ?></div>
                    <strong><?= e($heroPillTL['main']) ?></strong>
                </div>
            </div>
            <div class="hero-feature-pill bl">
                <span class="dot" style="background:#f0a830"></span>
                <div>
                    <div style="font-size:11px;color:#6b7280"><?= e($heroPillBL['sub']) ?></div>
                    <strong><?= e($heroPillBL['main']) ?></strong>
                </div>
            </div>
            <div class="hero-feature-pill br">
                <div>
                    <div style="font-size:11px;color:#6b7280"><?= e($heroPillBR['sub']) ?></div>
                    <strong><?= e($heroPillBR['main']) ?></strong>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- 信任条 -->
<?php if (!empty($trustBadges)): ?>
<div class="trust-bar">
    <div class="container">
        <div class="trust-badges">
            <?php foreach ($trustBadges as $tb): ?>
                <span class="trust-badge"><?= e($tb) ?></span>
            <?php endforeach; ?>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- 产品系列 -->
<section class="section" id="products">
    <div class="container">
        <div class="section-title">
            <div class="section-eyebrow"><?= e(cfg('products_eyebrow', 'PRODUCT SERIES')) ?></div>
            <h2><?= e(cfg('products_title', '盛木凡产品系列')) ?></h2>
            <p><?= nl2br(e(cfg('products_subtitle', '100% 原生木浆 · 4 层加厚 · 母婴可用'))) ?></p>
        </div>
        <div class="product-grid">
            <?php
            $defaultEmojis = ['🧻', '🌿', '💧'];
            $i = 0;
            foreach ($products as $p):
                $emoji = $defaultEmojis[$i] ?? '📦';
            ?>
            <div class="product-card">
                <div class="product-thumb">
                    <?php if (!empty($p['cover_image'])): ?>
                        <img src="<?= e($p['cover_image']) ?>" alt="<?= e($p['title']) ?>" style="width:100%;height:100%;object-fit:cover">
                    <?php else: ?>
                        <span style="font-size:80px"><?= $emoji ?></span>
                    <?php endif; ?>
                </div>
                <div class="product-body">
                    <h3><?= e($p['title']) ?></h3>
                    <p><?= e(str_sub($p['summary'] ?? strip_tags($p['content']), 80)) ?></p>
                    <a class="btn btn-primary" href="/content.php?slug=<?= e($p['slug']) ?>">查看详情</a>
                </div>
            </div>
            <?php $i++; endforeach; ?>

            <?php if (empty($products)): ?>
                <div style="grid-column:1/-1;text-align:center;padding:30px;color:#9ca3af">
                    暂无产品, 请到 <a href="/fmsmf/content.php">内容管理</a> 添加 type=知识库 / category=产品 的内容
                </div>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- 4大特性 - 从 tbs_feature 读 -->
<?php if (!empty($features)): ?>
<section class="section" style="background:var(--bg-soft)">
    <div class="container">
        <div class="section-title">
            <div class="section-eyebrow"><?= e(cfg('features_eyebrow', 'WHY SHENGMUFAN')) ?></div>
            <h2><?= e(cfg('features_title', '为什么选择盛木凡')) ?></h2>
            <p><?= e(cfg('features_subtitle', '从原料到工艺, 每一步都为宝宝娇嫩肌肤着想。')) ?></p>
        </div>
        <div class="features">
            <?php foreach ($features as $f): ?>
            <div class="feature">
                <div class="feature-icon"><i class="bi <?= e($f['icon'] ?: 'bi-star') ?>"></i></div>
                <h4><?= e($f['title']) ?></h4>
                <p><?= e($f['description']) ?></p>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- FAQ -->
<?php if (!empty($faqs)): ?>
<section class="section">
    <div class="container">
        <div class="section-title">
            <div class="section-eyebrow"><?= e(cfg('faq_eyebrow', 'FAQ')) ?></div>
            <h2><?= e(cfg('faq_title', '关于盛木凡的常见问题')) ?></h2>
            <p><?= e(cfg('faq_subtitle', '你想知道的, 都在这里。')) ?></p>
        </div>
        <div class="faq-list">
            <?php foreach ($faqs as $f): ?>
                <div class="faq-item">
                    <button class="faq-q"><?= e($f['title']) ?></button>
                    <div class="faq-a"><?= $f['content'] ?></div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- 最新文章 -->
<?php if (!empty($articles)): ?>
<section class="section" style="background:var(--bg-soft)">
    <div class="container">
        <div class="section-title">
            <div class="section-eyebrow"><?= e(cfg('kb_eyebrow', 'KNOWLEDGE & NEWS')) ?></div>
            <h2><?= e(cfg('kb_title', '知识库 · 资讯')) ?></h2>
            <p><?= e(cfg('kb_subtitle', '母婴用纸专业知识 · 行业资讯')) ?></p>
        </div>
        <div class="article-grid">
            <?php foreach ($articles as $a): ?>
                <a class="article-card" href="<?= $a['type'] === 'news' ? '/news.php?slug=' . e($a['slug']) : '/content.php?slug=' . e($a['slug']) ?>">
                    <div class="article-thumb">
                        <?php if (!empty($a['cover_image'])): ?>
                            <img src="<?= e($a['cover_image']) ?>" alt="<?= e($a['title']) ?>" style="width:100%;height:100%;object-fit:cover">
                        <?php else: ?>
                            📄
                        <?php endif; ?>
                    </div>
                    <div class="article-body">
                        <div class="meta">
                            <span class="tag tag-info" style="background:var(--primary-light);color:var(--primary-dark);padding:2px 8px;border-radius:4px;font-size:11px"><?= e($a['type']) ?></span>
                            <span style="margin-left:8px"><?= e(date('Y-m-d', strtotime($a['published_at'] ?? $a['created_at']))) ?></span>
                        </div>
                        <h3><?= e($a['title']) ?></h3>
                        <p><?= e(str_sub($a['summary'] ?? strip_tags($a['content']), 80)) ?></p>
                        <span style="color:var(--primary);font-size:13px;font-weight:500">阅读全文 →</span>
                    </div>
                </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- CTA -->
<section class="section" style="background:linear-gradient(135deg, var(--primary), var(--primary-dark));color:#fff;text-align:center">
    <div class="container">
        <h2 style="color:#fff;font-size:32px;margin:0 0 12px"><?= e(cfg('cta_eyebrow', '为家人选一张安心的纸巾')) ?></h2>
        <p style="font-size:16px;opacity:.9;margin:0 0 24px"><?= e(cfg('cta_subtitle', '100% 原生木浆 · 母婴可用 · 双国标认证')) ?></p>
        <a class="btn btn-lg" style="background:#fff;color:var(--primary-dark);font-weight:600" href="<?= e(cfg('cta_btn_url', '/products.php')) ?>"><?= e(cfg('cta_btn_text', '立即购买盛木凡')) ?></a>
    </div>
</section>

<?php require __DIR__ . '/footer.php'; ?>
