<?php
$pageTitle = '首页';
require_once 'header.php';
require_once 'config.php';

// 从数据库读取评价
try {
    $stmt = $pdo->query("SELECT author, role, content, avatar, rating FROM testimonials ORDER BY created_at DESC LIMIT 5");
    $testimonials = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $testimonials = [];
}
?>

<main class="site-main">
    
    <!-- 轮播图 -->
    <section class="hero-banner">
        <div class="slider-container">
            <div class="slide active">
                <div class="slide-content">
                    <h1>🌸 阳泉婚礼宝典</h1>
                    <p>一站式解决所有婚礼问题</p>
                    <a href="services.php" class="btn btn-primary">立即开始</a>
                </div>
            </div>
            <div class="slide">
                <div class="slide-content">
                    <h1>🎎 本地婚俗专家</h1>
                    <p>了解阳泉传统婚礼文化</p>
                    <a href="traditions.php" class="btn btn-secondary">了解更多</a>
                </div>
            </div>
            <div class="slide">
                <div class="slide-content">
                    <h1>💒 精选商家推荐</h1>
                    <p>阳泉本地最优质的婚庆服务商</p>
                    <a href="vendors.php" class="btn btn-primary">查看商家</a>
                </div>
            </div>
            <button class="slider-prev" id="sliderPrev"><i class="fas fa-chevron-left"></i></button>
            <button class="slider-next" id="sliderNext"><i class="fas fa-chevron-right"></i></button>
            <div class="slider-dots">
                <span class="dot active"></span>
                <span class="dot"></span>
                <span class="dot"></span>
            </div>
        </div>
    </section>

    <!-- 服务卡片 -->
    <section class="quick-services" id="services">
        <div class="container">
            <div class="section-title">
                <h2>💒 我们的服务</h2>
                <p>从筹备到礼成，全程陪伴</p>
            </div>
            <div class="service-grid">
                <a href="custom.php" class="service-card">
                    <div class="service-icon">🏮</div>
                    <h3>本地风俗查询</h3>
                    <p>阳泉婚嫁礼仪、择日、过大礼</p>
                    <span class="service-tag">热门</span>
                </a>
                <a href="budget.php" class="service-card">
                    <div class="service-icon">💰</div>
                    <h3>预算管理</h3>
                    <p>智能分项预算建议与追踪</p>
                </a>
                <a href="checklist.php" class="service-card">
                    <div class="service-icon">📋</div>
                    <h3>婚礼清单</h3>
                    <p>按时间节点规划筹备任务</p>
                </a>
                <a href="vendors.php" class="service-card">
                    <div class="service-icon">🏪</div>
                    <h3>商家推荐</h3>
                    <p>阳泉本地优质婚庆商家</p>
                </a>
                <a href="gallery.php" class="service-card">
                    <div class="service-icon">📸</div>
                    <h3>婚礼案例</h3>
                    <p>本地真实婚礼案例参考</p>
                </a>
                <a href="dating.php" class="service-card">
                    <div class="service-icon">💑</div>
                    <h3>婚恋交友</h3>
                    <p>寻找志同道合的另一半</p>
                </a>
                <a href="wedding_schedule.php" class="service-card">
                    <div class="service-icon">📋</div>
                    <h3>婚礼当日流程</h3>
                    <p>婚礼当天全流程安排指南</p>
                </a>
                <a href="parent_attire.php" class="service-card">
                    <div class="service-icon">👔</div>
                    <h3>父母衣着</h3>
                    <p>四季父母着装得体建议</p>
                </a>
                <a href="parent_speech.php" class="service-card">
                    <div class="service-icon">🎤</div>
                    <h3>父母致辞</h3>
                    <p>简单上口的婚礼台词范例</p>
                </a>
                <a href="almanac.php" class="service-card">
                    <div class="service-icon">📅</div>
                    <h3>老黄历</h3>
                    <p>每日宜忌、择良辰吉日</p>
                    <span class="service-tag">热门</span>
                </a>
                <a href="weather.php" class="service-card">
                    <div class="service-icon">🌤</div>
                    <h3>天气查询</h3>
                    <p>提前查询婚礼天气状况</p>
                </a>
                <a href="bazi.php" class="service-card">
                    <div class="service-icon">🔮</div>
                    <h3>八字测算</h3>
                    <p>八字命理解读与姻缘分析</p>
                </a>
                <a href="invitation_create.php" class="service-card">
                    <div class="service-icon">💌</div>
                    <h3>电子请柬</h3>
                    <p>在线制作浪漫婚礼请柬</p>
                    <span class="service-tag">新版</span>
                </a>
                <a href="tickets.php" class="service-card">
                    <div class="service-icon">🚄</div>
                    <h3>票务查询</h3>
                    <p>机票与高铁票一站式预订</p>
                </a>
                <a href="gallery_yulong.php" class="service-card">
                    <div class="service-icon">❄️</div>
                    <h3>雪山婚礼</h3>
                    <p>玉龙雪山户外婚礼策划</p>
                    <span class="service-tag">热门</span>
                </a>
            </div>
        </div>
    </section>

    <!-- 婚礼倒计时模块 -->
    <section class="wedding-tools">
        <div class="container">
            <div class="tools-grid">
                <div class="tool-card countdown-card">
                    <div class="tool-header">
                        <h3><i class="fas fa-hourglass-half"></i> 婚礼倒计时</h3>
                        <button id="editDateBtn" class="btn-small">修改日期</button>
                    </div>
                    <div class="countdown-display">
                        <div class="countdown-item">
                            <span id="countdownDays" class="countdown-number">--</span>
                            <span class="countdown-label">天</span>
                        </div>
                        <div class="countdown-item">
                            <span id="countdownHours" class="countdown-number">--</span>
                            <span class="countdown-label">时</span>
                        </div>
                        <div class="countdown-item">
                            <span id="countdownMinutes" class="countdown-number">--</span>
                            <span class="countdown-label">分</span>
                        </div>
                        <div class="countdown-item">
                            <span id="countdownSeconds" class="countdown-number">--</span>
                            <span class="countdown-label">秒</span>
                        </div>
                    </div>
                    <div class="date-picker-wrapper" id="datePickerWrapper" style="display:none;">
                        <input type="date" id="weddingDateInput" value="2025-10-01">
                        <button id="saveDateBtn" class="btn-primary btn-small">保存日期</button>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 动态用户评价 -->
    <section class="testimonials">
        <div class="container">
            <div class="section-title">
                <h2>💬 新人好评</h2>
                <p>真实用户的婚礼经验分享</p>
            </div>
            <div class="testimonial-slider">
                <?php if (!empty($testimonials)): ?>
                    <?php foreach ($testimonials as $t): ?>
                    <div class="testimonial-card">
                        <div class="testimonial-stars"><?php echo str_repeat('⭐', (int)$t['rating']); ?></div>
                        <p class="testimonial-text">"<?php echo htmlspecialchars($t['content']); ?>"</p>
                        <div class="testimonial-author">
                            <div class="author-avatar-placeholder"><?php echo htmlspecialchars(mb_substr($t['author'], 0, 1)); ?></div>
                            <div>
                                <strong><?php echo htmlspecialchars($t['author']); ?></strong>
                                <span><?php echo htmlspecialchars($t['role']); ?></span>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                <?php else: ?>
                    <p class="empty-state">暂无评价，快来分享你的经验吧！</p>
                <?php endif; ?>
            </div>
        </div>
    </section>
</main>

<?php require_once 'footer.php'; ?>