<?php
/**
 * 芋头CMS - 家具定制企业网站模板 - 产品列表
 */
if (!defined('ROOT_PATH')) { exit('Access Denied'); }
if (!isset($contentList)) {
    $contentList = $db->fetchAll("SELECT p.*, c.channel_name FROM {$db->table('product')} p LEFT JOIN {$db->table('channel')} c ON p.channel_id=c.id WHERE p.status=1 ORDER BY p.create_time DESC LIMIT 20");
}
$pageTitle = '产品列表';
$extraHead = '<style>.product-list-body { padding-top: 70px; }</style>';

require_once __DIR__ . '/../_header.php';
?>

<div class="product-list-body">
<div style="height:280px;background:linear-gradient(135deg,var(--dark) 0%,var(--primary-dark) 100%);display:flex;align-items:center;justify-content:center;margin-top:70px;">
<div style="text-align:center;color:white;">
<h1 style="font-size:36px;margin-bottom:10px;"><?php echo htmlspecialchars($channel['channel_name'] ?? ''); ?></h1>
<p style="opacity:0.7;font-size:14px;">当前位置：<a href="<?php echo getUrl('home'); ?>" style="color:white;">首页</a> &gt; <a href="<?php echo getUrl('channel', $id); ?>" style="color:white;"><?php echo htmlspecialchars($channel['channel_name'] ?? ''); ?></a></p>
</div>
</div>

<section class="section">
<div class="container">
<div class="product-grid">
<?php if (!empty($contentList)): foreach ($contentList as $p): ?>
<a href="<?php echo getUrl('product', $p['id']); ?>" class="product-card">
<div class="product-card-img">
<?php if (!empty($p['litpic'])): ?>
<img src="<?php echo htmlspecialchars($p['litpic']); ?>" alt="<?php echo htmlspecialchars($p['title']); ?>">
<?php else: ?>
<img src="https://picsum.photos/400/300?random=<?php echo $p['id']; ?>" alt="">
<?php endif; ?>
</div>
<div class="product-card-info">
<h3><?php echo htmlspecialchars($p['title']); ?></h3>
<?php if (!empty($p['price'])): ?>
<p class="price">¥<?php echo number_format($p['price'], 2); ?></p>
<?php endif; ?>
</div>
</a>
<?php endforeach; else: ?>
<div style="text-align:center;color:var(--gray-light);padding:60px 0;">暂无产品</div>
<?php endif; ?>
</div>

<span style="padding:8px 16px;color:var(--gray);">第 <?php echo $pp; ?> / <?php echo $totalPages; ?> 页</span>
<?php if ($pp < $totalPages): ?><a href="?m=product&id=<?php echo $id; ?>&page=<?php echo $pp+1; ?>" style="padding:8px 16px;border:1px solid var(--border);border-radius:4px;margin:0 4px;">下一页 ›</a><?php endif; ?>
</div>
<?php endif; ?>
</div>
</section>
</div>

<?php require_once __DIR__ . '/../_footer.php'; ?>
