<?php
// 设置 TDK
$page_title = '300462｜白酒资讯大全 婚宴升学乔迁满月宴选邑天下';
$page_description = '300462一站式查询白酒文化、白酒知识、白酒品牌、白酒新闻、啤酒资讯。适配全场景大小宴席，婚宴、满月宴、乔迁宴、升学宴办酒，宴席优选邑天下酒。';
$page_keywords = '300462,白酒网,白酒文化,白酒知识,白酒品牌,白酒新闻,啤酒,邑天下酒,宴席,婚宴,满月宴,乔迁宴,升学宴,大小宴席,宴席用酒';
$page_canonical = (defined('SITE_URL') ? SITE_URL : '') . '/';

require_once 'includes/header.php';

$carousel_news = get_news_with_images(4);
if (empty($carousel_news)) {
    $latest_all = get_news_list(1, 4);
    foreach ($latest_all as &$n) { $n['image'] = extract_first_image($n['content']); }
    $carousel_news = $latest_all;
}
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
$limit = 10;
$news_list = get_news_list($page, $limit);
$total = count_news();
$hot_news = get_hot_news(6);
$categories = get_categories();
?>

<!-- 面包屑 -->
<nav aria-label="breadcrumb" class="mb-3">
    <ol class="breadcrumb">
        <li class="breadcrumb-item active" aria-current="page">首页</li>
    </ol>
</nav>

<!-- 轮播图（同前，略） -->
<?php if (!empty($carousel_news)): ?>
<div id="heroCarousel" class="carousel slide mb-4" data-bs-ride="carousel">
    <div class="carousel-indicators">
        <?php foreach ($carousel_news as $i => $item): ?>
        <button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="<?= $i ?>" <?= $i==0 ? 'class="active" aria-current="true"' : '' ?>></button>
        <?php endforeach; ?>
    </div>
    <div class="carousel-inner rounded shadow">
        <?php foreach ($carousel_news as $i => $item): 
            $image = !empty($item['image']) ? $item['image'] : 'https://placehold.co/1200x400/2c3e50/white?text='.urlencode(mb_substr($item['title'],0,20));
        ?>
        <div class="carousel-item <?= $i==0 ? 'active' : '' ?>" style="height:350px; background: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)), url('<?= htmlspecialchars($image) ?>') center/cover no-repeat;">
            <div class="carousel-caption d-none d-md-block text-start" style="bottom:30px;">
                <h2><a href="/news/<?= $item['id'] ?>.html" class="text-white text-decoration-none"><?= htmlspecialchars($item['title']) ?></a></h2>
                <p><?= mb_substr(strip_tags($item['content']), 0, 100) ?>...</p>
                <small><?= date('Y-m-d', strtotime($item['created_at'])) ?> · 阅读 <?= $item['views'] ?></small>
            </div>
        </div>
        <?php endforeach; ?>
    </div>
    <button class="carousel-control-prev" type="button" data-bs-target="#heroCarousel" data-bs-slide="prev">
        <span class="carousel-control-prev-icon"></span>
    </button>
    <button class="carousel-control-next" type="button" data-bs-target="#heroCarousel" data-bs-slide="next">
        <span class="carousel-control-next-icon"></span>
    </button>
</div>
<?php endif; ?>

<!-- 分类导航条 -->
<div class="row mb-4">
    <div class="col-12">
        <div class="d-flex flex-wrap gap-2">
            <a href="/" class="btn btn-outline-primary btn-sm active">全部</a>
            <?php foreach ($categories as $cat): ?>
            <a href="/category/<?= $cat['id'] ?>.html" class="btn btn-outline-secondary btn-sm"><?= htmlspecialchars($cat['name']) ?></a>
            <?php endforeach; ?>
        </div>
    </div>
</div>

<!-- 主内容 -->
<h1 class="h4 mb-3 fw-bold">📡 最新资讯</h1>
<div class="row">
    <div class="col-lg-8">
        <?php foreach ($news_list as $news): 
            $img = extract_first_image($news['content']);
        ?>
        <article class="card mb-3 border-0 shadow-sm">
            <div class="row g-0">
                <?php if ($img): ?>
                <div class="col-md-4">
                    <a href="/news/<?= $news['id'] ?>.html" class="d-block h-100" style="background: url('<?= htmlspecialchars($img) ?>') center/cover no-repeat; min-height: 150px;" title="<?= htmlspecialchars($news['title']) ?>"></a>
                </div>
                <div class="col-md-8">
                <?php else: ?>
                <div class="col-12">
                <?php endif; ?>
                    <div class="card-body">
                        <h2 class="h5 card-title">
                            <a href="/news/<?= $news['id'] ?>.html" class="text-decoration-none text-dark fw-bold"><?= htmlspecialchars($news['title']) ?></a>
                        </h2>
                        <p class="card-text small text-muted mb-1">
                            <span class="badge bg-primary me-1"><?= htmlspecialchars($news['category_name'] ?? '综合') ?></span>
                            <time datetime="<?= date('c', strtotime($news['created_at'])) ?>"><?= date('m-d', strtotime($news['created_at'])) ?></time>
                            · 阅读 <?= $news['views'] ?>
                        </p>
                        <p class="card-text"><?= mb_substr(strip_tags($news['content']), 0, 120) ?>...</p>
                    </div>
                </div>
            </div>
        </article>
        <?php endforeach; ?>

        <!-- 分页 SEO 增强：rel prev/next -->
        <?php if ($total > $limit): ?>
        <nav>
        <?= pagination(count_news(), $page, 10, '/page/') ?>

            </ul>
        </nav>
        <?php endif; ?>
    </div>

    <!-- 侧边栏（同前） -->
    <div class="col-lg-4">
        <?php $ad_top = get_ads('home_sidebar'); if ($ad_top): ?>
        <div class="card mb-3 border-0 shadow-sm">
            <div class="card-body p-2 text-center">
                <?php if ($ad_top['type'] == 'image'): ?>
                    <a href="<?= htmlspecialchars($ad_top['link']) ?>" target="_blank" rel="nofollow"><img src="<?= htmlspecialchars($ad_top['content']) ?>" class="img-fluid rounded" alt="广告"></a>
                <?php else: echo $ad_top['content']; endif; ?>
            </div>
        </div>
        <?php endif; ?>

        <div class="card border-0 shadow-sm mb-3">
            <div class="card-header bg-warning text-dark fw-bold">🔥 热门排行</div>
            <ul class="list-group list-group-flush">
                <?php foreach ($hot_news as $idx => $hot): ?>
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <a href="/news/<?= $hot['id'] ?>.html" class="text-decoration-none text-dark text-truncate" style="max-width:80%;"><?= htmlspecialchars($hot['title']) ?></a>
                    <span class="badge bg-secondary rounded-pill"><?= $hot['views'] ?></span>
                </li>
                <?php endforeach; ?>
            </ul>
        </div>

        <div class="card border-0 shadow-sm">
            <div class="card-header bg-light">📌 快速浏览</div>
            <div class="card-body">
                <div class="d-flex flex-wrap gap-1">
                    <?php foreach ($categories as $cat): ?>
                    <a href="/category/<?= $cat['id'] ?>.html" class="badge bg-light text-dark text-decoration-none p-2"><?= htmlspecialchars($cat['name']) ?></a>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 结构化数据：WebSite -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "name": "新闻中心",
  "url": "<?= defined('SITE_URL') ? SITE_URL : '' ?>/"
}
</script>

<?php require_once 'includes/footer.php'; ?>
