<?php
$pageTitle = '婚礼当日流程安排';
require_once 'header.php';
require_once 'config.php';

// 按时段查询流程数据
try {
    $stmt = $pdo->query("SELECT * FROM wedding_day_schedule ORDER BY sort_order");
    $scheduleItems = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    // 按时段分组
    $grouped = [];
    $periodNames = ['morning' => '上午流程', 'noon' => '中午流程', 'afternoon' => '下午流程'];
    foreach ($scheduleItems as $item) {
        $grouped[$item['period']][] = $item;
    }
} catch (PDOException $e) {
    $scheduleItems = [];
    $grouped = [];
}
?>

<main class="site-main">

    <section class="page-banner">
        <div class="container">
            <h1>📋 婚礼当日流程安排</h1>
            <p>精心规划婚礼当天每一个环节，让大日子完美无缺</p>
        </div>
    </section>

    <section class="schedule-intro">
        <div class="container">
            <div class="schedule-summary">
                <div class="summary-card">
                    <div class="summary-icon">⏰</div>
                    <h3>贴心提醒</h3>
                    <p>以下为标准流程模板，您可根据实际情况灵活调整。建议提前与婚庆公司、酒店、司仪沟通确认各环节时间。</p>
                    <div class="download-actions">
                        <a href="downloads.php?action=download&type=schedule" class="btn-download-inline">
                            <i class="fas fa-download"></i> 下载Excel流程表
                        </a>
                        <a href="downloads.php?action=download&type=schedule_pdf" class="btn-download-inline btn-pdf">
                            <i class="fas fa-file-pdf"></i> 下载PDF版
                        </a>
                        <a href="downloads.php?action=download&type=roles" class="btn-download-inline btn-roles">
                            <i class="fas fa-users"></i> 下载角色分工表
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 动态流程表 -->
    <section class="schedule-timeline">
        <div class="container">
            
            <!-- 时段筛选 -->
            <div class="schedule-tabs">
                <button class="schedule-tab active" data-period="all">📅 全部</button>
                <button class="schedule-tab" data-period="morning">🌅 上午</button>
                <button class="schedule-tab" data-period="noon">☀️ 中午</button>
                <button class="schedule-tab" data-period="afternoon">🌤 下午</button>
            </div>

            <?php if (!empty($scheduleItems)): ?>
            <div class="schedule-table-wrapper">
                <table class="schedule-table">
                    <thead>
                        <tr>
                            <th style="width:12%;">⏱ 时间</th>
                            <th style="width:18%;">🎯 环节</th>
                            <th style="width:16%;">👤 负责人</th>
                            <th style="width:18%;">🤝 协助人员</th>
                            <th style="width:36%;">⚠️ 注意事项</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $currentPeriod = '';
                        foreach ($scheduleItems as $item):
                            $periodLabel = $periodNames[$item['period']] ?? $item['period'];
                            if ($currentPeriod !== $item['period']):
                                $currentPeriod = $item['period'];
                        ?>
                        <tr class="schedule-period-header" data-period="<?php echo $item['period']; ?>">
                            <td colspan="5">
                                <span class="period-badge">
                                    <?php echo $item['period'] === 'morning' ? '🌅' : ($item['period'] === 'noon' ? '☀️' : '🌤'); ?>
                                    <?php echo $periodLabel; ?>
                                </span>
                            </td>
                        </tr>
                        <?php endif; ?>
                        <tr class="schedule-row" data-period="<?php echo $item['period']; ?>">
                            <td class="schedule-time"><?php echo htmlspecialchars($item['time_slot']); ?></td>
                            <td class="schedule-segment"><?php echo htmlspecialchars($item['segment']); ?></td>
                            <td><?php echo htmlspecialchars($item['responsible']); ?></td>
                            <td><?php echo htmlspecialchars($item['helpers']); ?></td>
                            <td class="schedule-notes"><?php echo htmlspecialchars($item['notes']); ?></td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
            <?php else: ?>
            <p class="empty-state">暂无流程数据，请在数据库中添加。</p>
            <?php endif; ?>
        </div>
    </section>

    <!-- 关键角色分工表 -->
    <section class="schedule-roles">
        <div class="container">
            <h2>👥 关键角色分工表</h2>
            <p class="roles-intro">婚礼当天事务繁杂，提前明确分工才能有条不紊。建议提前1周将下表打印分发到各负责人手中。</p>
            <div class="roles-table-wrapper">
                <table class="roles-table">
                    <thead>
                        <tr>
                            <th style="width:12%;">角色</th>
                            <th style="width:18%;">负责人</th>
                            <th style="width:20%;">联系方式</th>
                            <th style="width:50%;">主要职责</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><span class="role-badge role-chief">总指挥</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>全程统筹协调，处理突发事件，各环节时间把控，与酒店/婚庆对接。是婚礼当天的"总负责人"。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-mc">司仪</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>主持婚礼仪式，把控仪式节奏，调动现场气氛。提前与新人沟通流程细节，准备主持词。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-groom">伴郎团</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>协助新郎迎亲堵门闯关，保管戒指和红包，陪同敬酒挡酒，配合互动环节。建议2-4人。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-bride">伴娘团</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>协助新娘换装补妆，设计堵门游戏，保管新娘随身物品，陪同敬酒引导。建议2-4人。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-sign">签到接待</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>引导宾客签到、写祝福卡，发放喜糖伴手礼，指引宾客入座。需熟悉席位安排，建议2人。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-money">礼金管理</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>收取并登记礼金红包，妥善保管，婚礼结束后交还新人父母。需细心可靠，建议由至亲担任。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-car">婚车调度</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>安排婚车装饰、确认发车时间与路线，协调司机、对讲机通讯，引导车队安全行驶。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-item">物品管理</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>清点保管婚品（烟酒糖茶、喜字、鞭炮等），搬运分发，婚宴结束后清点回收剩余物品。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-seat">引位员</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>熟悉席位图，引导宾客快速找到座位，协调临时加座需求。建议2-4人。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-photo">摄影摄像</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>全程跟拍婚礼精彩瞬间，包括化妆准备、迎亲、仪式、敬酒等环节。提前沟通必拍镜头清单。</td>
                        </tr>
                        <tr>
                            <td><span class="role-badge role-parent">双方父母</span></td>
                            <td class="editable-cell">________</td>
                            <td class="editable-cell">________</td>
                            <td>迎宾接待长辈亲友，上台致辞（可提前准备稿子），敬茶环节配合，送客时与新人一同答谢。</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <p class="roles-tip">💡 打印提示：将本表复制到 Word 中打印，填写各角色对应的亲友姓名与手机号，婚礼前一天发给所有相关人员确认。</p>
        </div>
    </section>

    <!-- 当日必备物品清单 -->
    <section class="schedule-checklist">
        <div class="container">
            <h2>✅ 当日必备物品清单</h2>
            <div class="schedule-checklist-grid">
                <div class="checklist-category">
                    <h3>👰 新娘物品</h3>
                    <ul>
                        <li>主婚纱 + 头纱</li>
                        <li>敬酒服 / 礼服</li>
                        <li>婚鞋（高跟+平底各一双）</li>
                        <li>首饰（项链、耳环、手镯）</li>
                        <li>隐形内衣 / 胸贴</li>
                        <li>补妆包（口红、粉底等）</li>
                        <li>手机充电宝</li>
                    </ul>
                </div>
                <div class="checklist-category">
                    <h3>🤵 新郎物品</h3>
                    <ul>
                        <li>西装套装</li>
                        <li>衬衫（备用一件）</li>
                        <li>领带 / 领结</li>
                        <li>皮鞋 + 袜子</li>
                        <li>戒指（交给伴郎保管）</li>
                        <li>手捧花</li>
                        <li>红包若干</li>
                    </ul>
                </div>
                <div class="checklist-category">
                    <h3>📋 其他必备</h3>
                    <ul>
                        <li>结婚证（拍照用）</li>
                        <li>誓言卡</li>
                        <li>对讲机</li>
                        <li>婚车装饰 + 路线图</li>
                        <li>鞭炮 / 电子鞭炮</li>
                        <li>喜糖 + 伴手礼</li>
                        <li>签到本 + 笔</li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

</main>

<script>
// 时段筛选
document.querySelectorAll('.schedule-tab').forEach(function(tab) {
    tab.addEventListener('click', function() {
        document.querySelectorAll('.schedule-tab').forEach(function(t) { t.classList.remove('active'); });
        this.classList.add('active');
        var period = this.getAttribute('data-period');
        document.querySelectorAll('.schedule-row, .schedule-period-header').forEach(function(row) {
            if (period === 'all' || row.getAttribute('data-period') === period) {
                row.style.display = '';
            } else {
                row.style.display = 'none';
            }
        });
    });
});
</script>

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