<?php
/**
 * 2026企业CMS - 默认模板首页
 */
$slides = db_query("SELECT * FROM `slides` WHERE `status`=1 ORDER BY `sort_order` ASC LIMIT 5");
$features = [
    ['icon' => '🚀', 'title' => '高效服务', 'desc' => '提供高效、专业的企业服务解决方案'],
    ['icon' => '💡', 'title' => '创新技术', 'desc' => '持续创新，引领行业发展方向'],
    ['icon' => '🤝', 'title' => '客户至上', 'desc' => '以客户需求为中心，提供优质服务'],
    ['icon' => '🏆', 'title' => '品质保证', 'desc' => '严格质量控制，确保服务品质'],
];
$hotProducts = db_query("SELECT * FROM `products` WHERE `status`=1 AND `is_hot`=1 ORDER BY `sort_order` ASC LIMIT 6");
$latestNews = db_query("SELECT * FROM `articles` WHERE `status`=1 ORDER BY `is_top` DESC, `published_at` DESC LIMIT 6");
$caseList = db_query("SELECT * FROM `cases` WHERE `status`=1 ORDER BY `sort_order` ASC LIMIT 4");
$teamMembers = db_query("SELECT * FROM `team` WHERE `status`=1 ORDER BY `sort_order` ASC LIMIT 4");
?>

<!-- 幻灯片轮播 -->
<?php if ($slides): ?>
<div class="slider">
    <?php foreach ($slides as $i => $slide): ?>
    <div class="slide-item <?php echo $i==0?'active':''; ?>" style="background:linear-gradient(135deg,#2c82e0,#1a6bc4)">
        <div>
            <h2><?php echo xss_clean($slide['title'] ?: '欢迎来到' . SITE_NAME); ?></h2>
            <p><?php echo xss_clean($slide['description'] ?: SITE_SLOGAN); ?></p>
            <?php if ($slide['url']): ?>
            <a href="<?php echo $slide['url']; ?>" class="btn">了解更多</a>
            <?php endif; ?>
        </div>
    </div>
<?php endforeach; ?>
</div>
<?php endif; ?>

<!-- 核心优势 -->
<div class="main-content">
    <div class="container">
        <div class="section">
            <h2 class="section-title">核心优势</h2>
            <div class="grid" style="grid-template-columns:repeat(4,1fr);">
                <?php foreach ($features as $f): ?>
                <div class="card" style="text-align:center;padding:30px;">
                    <div style="font-size:48px;margin-bottom:15px;"><?php echo $f['icon']; ?></div>
                    <h3 style="font-size:18px;margin-bottom:10px;"><?php echo $f['title']; ?></h3>
                    <p style="color:#666;font-size:14px;"><?php echo $f['desc']; ?></p>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
        
        <!-- 热门产品 -->
        <?php if ($hotProducts): ?>
        <div class="section">
            <h2 class="section-title">热门产品</h2>
            <div class="grid">
                <?php foreach ($hotProducts as $p): ?>
                <div class="card">
                    <a href="<?php echo cms_url('product', ['slug' => $p['slug']]); ?>">
                        <div class="card-img">
                            <?php if ($p['cover_image']): ?>
                            <img src="<?php echo $p['cover_image']; ?>" alt="<?php echo xss_clean($p['title']); ?>">
                            <?php endif; ?>
                        </div>
                        <div class="card-body">
                            <div class="card-title"><?php echo xss_clean($p['title']); ?></div>
                            <div class="card-desc"><?php echo xss_clean(str_cut($p['summary'],80)); ?></div>
                            <div class="card-meta">
                                <?php if ($p['price']): ?>
                                <span style="color:#e74c3c;font-weight:bold;font-size:16px;">¥<?php echo $p['price']; ?></span>
                                <?php endif; ?>
                            </div>
                        </div>
                    </a>
                </div>
                <?php endforeach; ?>
            </div>
            <div style="text-align:center;margin-top:30px;">
                <a href="<?php echo cms_url('products'); ?>" class="btn">查看全部产品</a>
            </div>
        </div>
        <?php endif; ?>
        
        <!-- 最新资讯 -->
        <?php if ($latestNews): ?>
        <div class="section">
            <h2 class="section-title">最新资讯</h2>
            <div class="article-list">
                <?php foreach ($latestNews as $a): ?>
                <div class="article-item">
                    <?php if ($a['cover_image']): ?>
                    <div class="article-thumb">
                        <a href="<?php echo cms_url('article', ['slug' => $a['slug']]); ?>">
                            <img src="<?php echo $a['cover_image']; ?>" alt="<?php echo xss_clean($a['title']); ?>">
                        </a>
                    </div>
                    <?php endif; ?>
                    <div class="article-info">
                        <div class="article-title">
                            <a href="<?php echo cms_url('article', ['slug' => $a['slug']]); ?>"><?php echo xss_clean($a['title']); ?></a>
                        </div>
                        <div class="article-summary"><?php echo xss_clean(str_cut($a['summary'] ?: strip_tags($a['content']), 120)); ?></div>
                        <div class="article-meta">
                            <span>发布时间：<?php echo date('Y-m-d', strtotime($a['published_at'] ?: $a['created_at'])); ?></span>
                            <span>浏览量：<?php echo $a['views']; ?></span>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
            <div style="text-align:center;margin-top:30px;">
                <a href="<?php echo cms_url('news'); ?>" class="btn">查看全部资讯</a>
            </div>
        </div>
        <?php endif; ?>
        
        <!-- 成功案例 -->
        <?php if ($caseList): ?>
        <div class="section">
            <h2 class="section-title">成功案例</h2>
            <div class="grid">
                <?php foreach ($caseList as $c): ?>
                <div class="card">
                    <a href="<?php echo cms_url('case', ['slug' => $c['slug']]); ?>">
                        <div class="card-img">
                            <?php if ($c['cover_image']): ?>
                            <img src="<?php echo $c['cover_image']; ?>" alt="<?php echo xss_clean($c['title']); ?>">
                            <?php endif; ?>
                        </div>
                        <div class="card-body">
                            <div class="card-title"><?php echo xss_clean($c['title']); ?></div>
                            <div class="card-desc"><?php echo xss_clean(str_cut($c['summary'],80)); ?></div>
                        </div>
                    </a>
                </div>
                <?php endforeach; ?>
            </div>
            <div style="text-align:center;margin-top:30px;">
                <a href="<?php echo cms_url('cases'); ?>" class="btn">查看全部案例</a>
            </div>
        </div>
        <?php endif; ?>
        
        <!-- 团队成员 -->
        <?php if ($teamMembers): ?>
        <div class="section">
            <h2 class="section-title">团队成员</h2>
            <div class="grid" style="grid-template-columns:repeat(4,1fr);">
                <?php foreach ($teamMembers as $m): ?>
                <div class="card" style="text-align:center;padding:20px;">
                    <div style="width:100px;height:100px;border-radius:50%;overflow:hidden;margin:0 auto 15px;background:#eee;">
                        <?php if ($m['avatar']): ?>
                        <img src="<?php echo $m['avatar']; ?>" alt="<?php echo xss_clean($m['name']); ?>" style="width:100%;height:100%;object-fit:cover;">
                        <?php endif; ?>
                    </div>
                    <h3 style="font-size:16px;margin-bottom:5px;"><?php echo xss_clean($m['name']); ?></h3>
                    <p style="color:#2c82e0;font-size:13px;margin-bottom:10px;"><?php echo xss_clean($m['position']); ?></p>
                    <p style="color:#666;font-size:13px;"><?php echo xss_clean(str_cut($m['bio'],50)); ?></p>
                </div>
                <?php endforeach; ?>
            </div>
            <div style="text-align:center;margin-top:30px;">
                <a href="<?php echo cms_url('team'); ?>" class="btn">查看全部成员</a>
            </div>
        </div>
        <?php endif; ?>
    </div>
</div>
