<?php
/**
 * 2026企业CMS - 默认模板产品详情页
 */
$pageDescription = $product['summary'] ?: strip_tags(mb_substr($product['content'],0,200,'UTF-8'));
$pageKeywords = $product['seo_keywords'];
$breadcrumbItems = [
    ['title' => '产品中心', 'url' => cms_url('products')],
    ['title' => $product['title']]
];
?>
<?php echo breadcrumb($breadcrumbItems); ?>

<div class="main-content">
    <div class="container" style="display:flex;gap:30px;">
        <div style="flex:1;">
            <div class="article-detail">
                <div style="display:flex;gap:40px;margin-bottom:40px;">
                    <!-- 产品图片 -->
                    <div style="width:400px;flex-shrink:0;">
                        <div style="width:100%;height:350px;background:#f5f5f5;border-radius:8px;overflow:hidden;display:flex;align-items:center;justify-content:center;">
                            <?php if ($product['cover_image']): ?>
                            <img src="<?php echo $product['cover_image']; ?>" alt="<?php echo xss_clean($product['title']); ?>" style="width:100%;height:100%;object-fit:cover;">
                            <?php else: ?>
                            <span style="font-size:80px;color:#ccc;">📦</span>
                            <?php endif; ?>
                        </div>
                        <!-- 图集 -->
                        <?php if ($product['gallery']): ?>
                        <?php $gallery = json_decode($product['gallery'], true); ?>
                        <div style="display:flex;gap:10px;margin-top:10px;">
                            <?php foreach ($gallery as $img): ?>
                            <div style="width:60px;height:60px;background:#f5f5f5;border-radius:4px;overflow:hidden;">
                                <img src="<?php echo $img; ?>" style="width:100%;height:100%;object-fit:cover;">
                            </div>
                            <?php endforeach; ?>
                        </div>
                        <?php endif; ?>
                    </div>
                    
                    <!-- 产品信息 -->
                    <div style="flex:1;">
                        <h1 style="font-size:28px;margin-bottom:15px;color:#333;"><?php echo xss_clean($product['title']); ?></h1>
                        
                        <?php if ($product['price']): ?>
                        <div style="margin-bottom:15px;">
                            <span style="font-size:28px;color:#e74c3c;font-weight:bold;">¥<?php echo $product['price']; ?></span>
                            <?php if ($product['original_price'] && $product['original_price'] > $product['price']): ?>
                            <span style="font-size:16px;color:#999;text-decoration:line-through;margin-left:10px;">¥<?php echo $product['original_price']; ?></span>
                            <?php endif; ?>
                        </div>
                        <?php endif; ?>
                        
                        <div style="color:#666;font-size:14px;line-height:2;">
                            <?php if ($product['sku']): ?><div>商品编号：<?php echo xss_clean($product['sku']); ?></div><?php endif; ?>
                            <?php if ($product['stock'] !== null): ?><div>库存：<?php echo $product['stock']; ?> <?php echo $product['unit'] ?: '件'; ?></div><?php endif; ?>
                            <div>销量：<?php echo $product['sales']; ?></div>
                            <div>浏览量：<?php echo $product['views']; ?></div>
                        </div>
                        
                        <div style="margin-top:30px;display:flex;gap:15px;">
                            <button style="padding:12px 40px;background:#2c82e0;color:#fff;border:none;border-radius:4px;font-size:16px;cursor:pointer;">立即咨询</button>
                            <button style="padding:12px 40px;background:#fff;color:#2c82e0;border:2px solid #2c82e0;border-radius:4px;font-size:16px;cursor:pointer;">收藏</button>
                        </div>
                    </div>
                </div>
                
                <!-- 产品详情 -->
                <div style="border-top:1px solid #eee;padding-top:30px;">
                    <h3 style="font-size:20px;margin-bottom:20px;color:#333;">产品详情</h3>
                    <div class="content">
                        <?php echo $product['content']; ?>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- 侧边栏 -->
        <div class="sidebar">
            <div class="widget">
                <h3 class="widget-title">热门产品</h3>
                <ul style="list-style:none;">
                    <?php $hotProducts = db_query("SELECT `title`,`slug` FROM `products` WHERE `status`=1 AND `is_hot`=1 ORDER BY `sort_order` ASC LIMIT 5"); ?>
                    <?php foreach ($hotProducts as $hp): ?>
                    <li style="padding:8px 0;border-bottom:1px solid #eee;">
                        <a href="<?php echo cms_url('product', ['slug' => $hp['slug']]); ?>"><?php echo xss_clean($hp['title']); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
            
            <div class="widget">
                <h3 class="widget-title">推荐产品</h3>
                <ul style="list-style:none;">
                    <?php $recProducts = db_query("SELECT `title`,`slug` FROM `products` WHERE `status`=1 AND `is_recommend`=1 LIMIT 5"); ?>
                    <?php foreach ($recProducts as $rp): ?>
                    <li style="padding:8px 0;border-bottom:1px solid #eee;">
                        <a href="<?php echo cms_url('product', ['slug' => $rp['slug']]); ?>"><?php echo xss_clean($rp['title']); ?></a>
                    </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        </div>
    </div>
</div>
