<?php
/**
 * 首页模板（优化版）
 */
?>
<!-- 首页内容区（优化版）- 企业CMS -->

<!-- 特色功能板块 -->
<section class="features" aria-label="特色功能" style="padding: var(--space-16) 0; background: var(--color-bg-primary);">
    <div class="container">
        <h2 style="font-size: var(--font-size-2xl); font-weight: 600; text-align: center; margin-bottom: var(--space-4); color: var(--color-text-primary);">我们的服务</h2>
        <p style="text-align: center; color: var(--color-text-secondary); max-width: 600px; margin: 0 auto var(--space-12); font-size: var(--font-size-lg);">专业团队为企业提供一站式数字化解决方案</p>
        
        <div class="card-grid">
            <?php
            $services = db_query("SELECT * FROM pages WHERE category = 'service' AND status = 1 ORDER BY sort_order LIMIT 6");
            if (empty($services)) {
                // 默认服务卡片
                $default_services = [
                    ['title' => '企业官网建设', 'icon' => '🌐', 'desc' => '响应式设计，多终端适配，提升企业品牌形象'],
                    ['title' => '内容管理系统', 'icon' => '📝', 'desc' => '可视化编辑，多级权限管理，高效内容运营'],
                    ['title' => '产品展示平台', 'icon' => '🛍️', 'desc' => '精美的产品展示，支持分类筛选和搜索'],
                    ['title' => '新闻资讯发布', 'icon' => '📰', 'desc' => '多渠道内容分发，SEO优化，提升搜索引擎排名'],
                    ['title' => '在线留言系统', 'icon' => '💬', 'desc' => '智能表单生成，实时消息提醒，不错过任何商机'],
                    ['title' => '数据分析报告', 'icon' => '📊', 'desc' => '访问统计，用户行为分析，数据驱动决策'],
                ];
                foreach ($default_services as $i => $service):
            ?>
            <div class="card" style="padding: var(--space-8); text-align: center;">
                <div style="font-size: 2.5rem; margin-bottom: var(--space-4);"><?php echo $service['icon']; ?></div>
                <h3 style="font-size: var(--font-size-lg); font-weight: 600; margin-bottom: var(--space-3); color: var(--color-text-primary);"><?php echo $service['title']; ?></h3>
                <p style="font-size: var(--font-size-sm); color: var(--color-text-secondary); line-height: 1.6;"><?php echo $service['desc']; ?></p>
            </div>
            <?php
                endforeach;
            } else {
                foreach ($services as $service):
            ?>
            <div class="card" style="padding: var(--space-8); text-align: center;">
                <h3 style="font-size: var(--font-size-lg); font-weight: 600; margin-bottom: var(--space-3); color: var(--color-text-primary);"><?php echo htmlspecialchars($service['title'], ENT_QUOTES, 'UTF-8'); ?></h3>
                <p style="font-size: var(--font-size-sm); color: var(--color-text-secondary); line-height: 1.6;"><?php echo htmlspecialchars($service['content'], ENT_QUOTES, 'UTF-8'); ?></p>
            </div>
            <?php
                endforeach;
            }
            ?>
        </div>
    </div>
</section>

<!-- 最新产品板块 -->
<section class="products" aria-label="最新产品" style="padding: var(--space-16) 0; background: var(--color-bg-secondary);">
    <div class="container">
        <h2 style="font-size: var(--font-size-2xl); font-weight: 600; text-align: center; margin-bottom: var(--space-4); color: var(--color-text-primary);">最新产品</h2>
        <p style="text-align: center; color: var(--color-text-secondary); max-width: 600px; margin: 0 auto var(--space-12); font-size: var(--font-size-lg);">精选优质产品，助力企业高效运营</p>
        
        <div class="card-grid">
            <?php
            $products = db_query("SELECT * FROM products WHERE status = 1 ORDER BY created_at DESC LIMIT 6");
            foreach ($products as $product):
            ?>
            <article class="card">
                <?php if (!empty($product['image'])): ?>
                <img src="<?php echo htmlspecialchars($product['image'], ENT_QUOTES, 'UTF-8'); ?>" alt="<?php echo htmlspecialchars($product['name'], ENT_QUOTES, 'UTF-8'); ?>" class="card-img">
                <?php endif; ?>
                <div class="card-body">
                    <h3 class="card-title"><a href="/product/<?php echo $product['id']; ?>.html" style="color: inherit; text-decoration: none;"><?php echo htmlspecialchars($product['name'], ENT_QUOTES, 'UTF-8'); ?></a></h3>
                    <p class="card-text"><?php echo mb_substr(strip_tags($product['description']), 0, 100); ?>...</p>
                    <a href="/product/<?php echo $product['id']; ?>.html" class="btn btn-secondary" style="margin-top: var(--space-4);">查看详情</a>
                </div>
            </article>
            <?php endforeach; ?>
        </div>
        
        <div style="text-align: center; margin-top: var(--space-12);">
            <a href="<?php echo cms_url('products'); ?>" class="btn btn-primary btn-lg">查看全部产品</a>
        </div>
    </div>
</section>

<!-- 最新新闻板块 -->
<section class="news" aria-label="最新新闻" style="padding: var(--space-16) 0; background: var(--color-bg-primary);">
    <div class="container">
        <h2 style="font-size: var(--font-size-2xl); font-weight: 600; text-align: center; margin-bottom: var(--space-4); color: var(--color-text-primary);">最新动态</h2>
        <p style="text-align: center; color: var(--color-text-secondary); max-width: 600px; margin: 0 auto var(--space-12); font-size: var(--font-size-lg);">了解企业最新资讯和行业动态</p>
        
        <div class="card-grid">
            <?php
            $articles = db_query("SELECT a.*, c.name as cat_name FROM articles a LEFT JOIN categories c ON a.category_id = c.id WHERE a.status = 1 ORDER BY a.created_at DESC LIMIT 3");
            foreach ($articles as $article):
            ?>
            <article class="card">
                <?php if (!empty($article['cover_image'])): ?>
                <img src="<?php echo htmlspecialchars($article['cover_image'], ENT_QUOTES, 'UTF-8'); ?>" alt="<?php echo htmlspecialchars($article['title'], ENT_QUOTES, 'UTF-8'); ?>" class="card-img">
                <?php endif; ?>
                <div class="card-body">
                    <div style="font-size: var(--font-size-xs); color: var(--color-text-tertiary); margin-bottom: var(--space-2);">
                        <?php echo htmlspecialchars($article['cat_name'] ?? '未分类', ENT_QUOTES, 'UTF-8'); ?> · <?php echo date('Y-m-d', strtotime($article['created_at'])); ?>
                    </div>
                    <h3 class="card-title"><a href="/article/<?php echo $article['id']; ?>.html" style="color: inherit; text-decoration: none;"><?php echo htmlspecialchars($article['title'], ENT_QUOTES, 'UTF-8'); ?></a></h3>
                    <p class="card-text"><?php echo mb_substr(strip_tags($article['content']), 0, 80); ?>...</p>
                    <a href="/article/<?php echo $article['id']; ?>.html" style="font-size: var(--font-size-sm); color: var(--color-primary); text-decoration: none; font-weight: 500;">阅读更多 →</a>
                </div>
            </article>
            <?php endforeach; ?>
        </div>
        
        <div style="text-align: center; margin-top: var(--space-12);">
            <a href="<?php echo cms_url('news'); ?>" class="btn btn-primary btn-lg">查看全部新闻</a>
        </div>
    </div>
</section>

<!-- 联系我们板块（简化）-->
<section class="contact-brief" aria-label="联系我们" style="padding: var(--space-16) 0; background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%); color: var(--color-text-inverse); text-align: center;">
    <div class="container">
        <h2 style="font-size: var(--font-size-2xl); font-weight: 600; margin-bottom: var(--space-4);">准备好开始了吗？</h2>
        <p style="font-size: var(--font-size-lg); opacity: 0.9; max-width: 600px; margin: 0 auto var(--space-8);">联系我们，获取专属解决方案和免费试用</p>
        <div style="display: flex; gap: var(--space-4); justify-content: center; flex-wrap: wrap;">
            <a href="<?php echo cms_url('contact'); ?>" class="btn btn-white btn-lg">立即咨询</a>
            <a href="tel:<?php echo get_setting('contact_phone', '13874944449'); ?>" class="btn btn-secondary btn-lg" style="color: var(--color-text-inverse); border-color: rgba(255,255,255,0.5);">📞 电话咨询</a>
        </div>
    </div>
</section>

