<?php
header('Content-Type: text/html; charset=utf-8');
echo "<h2>🎯 婚礼数字人系统状态检测</h2>";
echo "<hr>";

// 1. 检查数据库连接
echo "<h3>📦 数据库连接</h3>";
try {
    require_once 'config.php';
    echo "<p style='color:green;'>✓ 数据库连接成功</p>";
    
    // 检查视频表是否存在
    $stmt = $pdo->query("SHOW TABLES LIKE 'video_assets'");
    if ($stmt->rowCount() > 0) {
        echo "<p style='color:green;'>✓ video_assets 表存在</p>";
        
        // 查询视频记录
        $stmt = $pdo->query("SELECT * FROM video_assets");
        $videos = $stmt->fetchAll(PDO::FETCH_ASSOC);
        echo "<p>📹 视频记录数量: " . count($videos) . "</p>";
        foreach ($videos as $v) {
            echo "<p>- " . $v['video_name'] . " (" . $v['video_type'] . ") - " . $v['duration'] . "秒</p>";
        }
    } else {
        echo "<p style='color:red;'>✗ video_assets 表不存在</p>";
    }
} catch (Exception $e) {
    echo "<p style='color:red;'>✗ 数据库连接失败: " . $e->getMessage() . "</p>";
}

echo "<hr>";

// 2. 检查视频目录
echo "<h3>📂 视频目录</h3>";
$dirs = ['videos/', 'videos/opening/', 'videos/host/'];
foreach ($dirs as $dir) {
    if (is_dir($dir)) {
        echo "<p style='color:green;'>✓ 目录存在: " . $dir . "</p>";
        $files = scandir($dir);
        $videoFiles = array_filter($files, function($f) {
            return preg_match('/\.(mp4|webm|ogg)$/i', $f);
        });
        if (!empty($videoFiles)) {
            echo "<p>  视频文件:</p>";
            foreach ($videoFiles as $f) {
                $size = filesize($dir . $f);
                echo "<p>  - " . $f . " (" . round($size / 1024 / 1024, 2) . "MB)</p>";
            }
        }
    } else {
        echo "<p style='color:red;'>✗ 目录不存在: " . $dir . "</p>";
    }
}

echo "<hr>";

// 3. 检查关键文件
echo "<h3>📄 关键文件</h3>";
$files = [
    'digital_human_host.php',
    'digital_human_screen.php',
    'api/api_router.php',
    'VIDEO_INTEGRATION_GUIDE.md'
];
foreach ($files as $file) {
    if (file_exists($file)) {
        echo "<p style='color:green;'>✓ 文件存在: " . $file . "</p>";
    } else {
        echo "<p style='color:red;'>✗ 文件不存在: " . $file . "</p>";
    }
}

echo "<hr>";
echo "<h3>🌐 访问地址</h3>";
echo "<p>主持端管理: <a href='digital_human_host.php' target='_blank'>digital_human_host.php</a></p>";
echo "<p>大屏展示: <a href='digital_human_screen.php' target='_blank'>digital_human_screen.php</a></p>";
echo "<p>API测试: <a href='api/api_router.php/video/assets' target='_blank'>视频API</a></p>";
?>
