<?php
$title = $cat ? $cat['name'] : '产品中心';
$sub = $cat ? $cat['description'] : '水冷循环 / 相变蓄冷 / 涡扇风冷，覆盖全场景降温需求';
?>
<section class="page-hero">
    <div class="container">
        <h1><?php echo e($title); ?></h1>
        <p><?php echo e($sub); ?></p>
    </div>
</section>
<div class="container">
    <nav class="breadcrumb"><a href="<?php echo site_url(); ?>">首页</a> / 产品中心</nav>
</div>
<section class="section" style="padding-top:20px">
    <div class="container">
        <div style="display:flex;gap:10px;flex-wrap:wrap;margin-bottom:34px">
            <a class="tag" style="<?php echo !$activeCat ? 'background:var(--c-primary);color:#fff' : '' ?>" href="<?php echo site_url('products'); ?>">全部</a>
            <?php foreach ($categories as $c): ?>
                <a class="tag" style="<?php echo $activeCat == $c['id'] ? 'background:var(--c-primary);color:#fff' : '' ?>" href="<?php echo site_url('products?cat=' . $c['id']); ?>"><?php echo e($c['name']); ?></a>
            <?php endforeach; ?>
        </div>
        <?php if (empty($products)): ?><p style="color:var(--c-muted)">该分类暂无产品。</p><?php endif; ?>
        <div class="product-grid">
            <?php foreach ($products as $p): ?>
                <div class="product-card reveal">
                    <a class="product-link" href="<?php echo site_url('products/' . $p['slug']); ?>">
                        <?php if (!empty($p['cover'])): ?>
                        <div class="product-thumb"><img src="<?php echo e(site_url($p['cover'])); ?>" alt="<?php echo e($p['name']); ?>"></div>
                        <?php else: ?>
                        <div class="product-thumb" style="background:<?php echo gradient($p['id']); ?>">❄</div>
                        <?php endif; ?>
                        <div class="product-body">
                            <div class="product-name"><?php echo e($p['name']); ?></div>
                            <div class="product-sum"><?php echo e($p['summary']); ?></div>
                            <div class="product-meta">
                                <div class="product-price">¥<?php echo e($p['price']); ?> <small>起</small></div>
                            </div>
                        </div>
                    </a>
                    <div class="product-actions">
                        <a class="btn btn-primary magnetic" href="<?php echo site_url('order/checkout/' . $p['slug']); ?>">立即购买</a>
                        <a class="btn btn-ghost" href="<?php echo site_url('products/' . $p['slug']); ?>">查看</a>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
