<?php
// 必须首先加载配置文件
require_once dirname(__DIR__, 2) . '/config.php';

// 不需要登录即可查看，移除登录检查

// 获取系统版本信息（从数据库读取）
$sys_version = getSiteConfig('sys_version') ?? '1.0.0';
$php_version = PHP_VERSION;
$mysql_version = $db->fetchOne("SELECT VERSION() as ver")['ver'] ?? '未知';
$server_software = $_SERVER['SERVER_SOFTWARE'] ?? '未知';

// 获取更新日志（只显示启用的）
$changelog = $db->fetchAll("
    SELECT * FROM changelog 
    WHERE status = 1 
    ORDER BY release_date DESC, id DESC 
    LIMIT 10
");
?>
        <?php include 'header.php'; ?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>版本信息 - 麟泓授权系统</title>
    <link rel="stylesheet" href="/assets/css/style.css">
    <link rel="stylesheet" href="/assets/css/dark.css" id="dark-theme" disabled>
    <script src="/assets/js/main.js" defer></script>
</head>
<body>
    <div class="front-container">
        
        <main class="front-main">
            <div class="version-container">
                <div class="version-header">
                    <h2>系统版本信息</h2>
                    <p>当前程序版本及运行环境信息</p>
                </div>

                <div class="version-card">
                    <div class="version-icon">🚀</div>
                    <h3>麟泓授权系统</h3>
                    <div class="version-badge">v<?php echo htmlspecialchars($sys_version); ?></div>
                    <p class="version-desc">专业软件授权管理平台，为开发者提供安全、稳定、高效的授权解决方案。</p>
                </div>

                <div class="info-grid">
                    <div class="info-item">
                        <div class="info-icon">📦</div>
                        <div class="info-content">
                            <div class="info-label">程序版本</div>
                            <div class="info-value">v<?php echo htmlspecialchars($sys_version); ?></div>
                            <div class="info-date">最后更新：<?php echo date('Y-m-d'); ?></div>
                        </div>
                    </div>
                    <div class="info-item">
                        <div class="info-icon">🐘</div>
                        <div class="info-content">
                            <div class="info-label">PHP 版本</div>
                            <div class="info-value"><?php echo htmlspecialchars($php_version); ?></div>
                            <div class="info-status <?php echo version_compare(PHP_VERSION, '8.0.0', '>=') ? 'status-good' : 'status-warning'; ?>">
                                <?php echo version_compare(PHP_VERSION, '8.0.0', '>=') ? '✓ 满足要求' : '⚠ 建议升级到 PHP 8.0+'; ?>
                            </div>
                        </div>
                    </div>
                    <div class="info-item">
                        <div class="info-icon">🗄️</div>
                        <div class="info-content">
                            <div class="info-label">MySQL 版本</div>
                            <div class="info-value"><?php echo htmlspecialchars($mysql_version); ?></div>
                            <div class="info-status status-good">✓ 运行正常</div>
                        </div>
                    </div>
                    <div class="info-item">
                        <div class="info-icon">🌐</div>
                        <div class="info-content">
                            <div class="info-label">Web 服务器</div>
                            <div class="info-value"><?php echo htmlspecialchars($server_software); ?></div>
                        </div>
                    </div>
                </div>

                <div class="feature-list">
                    <h3>系统特性</h3>
                    <div class="feature-grid">
                        <div class="feature-tag">🔐 授权验证</div>
                        <div class="feature-tag">💳 在线支付</div>
                        <div class="feature-tag">📦 资源下载</div>
                        <div class="feature-tag">🎫 工单系统</div>
                        <div class="feature-tag">👥 会员管理</div>
                        <div class="feature-tag">📊 数据统计</div>
                        <div class="feature-tag">🌙 深色模式</div>
                        <div class="feature-tag">📱 移动适配</div>
                        <div class="feature-tag">👨‍💻 代理中心</div>
                    </div>
                </div>

                <div class="update-log">
                    <h3>更新日志</h3>
                    <?php if (empty($changelog)): ?>
                        <p style="color: var(--text-muted); text-align: center; padding: 40px;">暂无更新日志</p>
                    <?php else: ?>
                        <?php foreach ($changelog as $log): ?>
                            <div class="log-item <?php echo $log['is_featured'] ? 'featured' : ''; ?>">
                                <div class="log-version">
                                    v<?php echo htmlspecialchars($log['version']); ?>
                                    <?php if ($log['is_featured']): ?>
                                        <span class="featured-badge">⭐ 重要更新</span>
                                    <?php endif; ?>
                                </div>
                                <div class="log-date"><?php echo $log['release_date']; ?></div>
                                <div class="log-content">
                                    <?php 
                                    $lines = explode("\n", $log['content']);
                                    echo '<ul>';
                                    foreach ($lines as $line) {
                                        $line = trim($line);
                                        if (!empty($line)) {
                                            echo '<li>' . htmlspecialchars($line) . '</li>';
                                        }
                                    }
                                    echo '</ul>';
                                    ?>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </div>
            </div>
        </main>
        
        <?php include 'footer.php'; ?>
    </div>
</body>
</html>

<style>
.version-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}
.version-header {
    text-align: center;
    margin-bottom: 30px;
}
.version-header h2 {
    font-size: 28px;
    margin-bottom: 8px;
    color: var(--text-primary);
}
.version-header p {
    color: var(--text-secondary);
}
.version-card {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--bg-primary) 100%);
    border-radius: 24px;
    padding: 40px;
    text-align: center;
    margin-bottom: 30px;
    border: 1px solid var(--border-color);
}
.version-icon {
    font-size: 64px;
    margin-bottom: 20px;
}
.version-card h3 {
    font-size: 28px;
    margin-bottom: 12px;
    color: var(--text-primary);
}
.version-badge {
    display: inline-block;
    background: var(--primary-color);
    color: white;
    padding: 6px 20px;
    border-radius: 30px;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
}
.version-desc {
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto;
    line-height: 1.6;
}
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}
.info-item {
    background: var(--bg-primary);
    border-radius: 20px;
    padding: 24px;
    display: flex;
    gap: 16px;
    align-items: flex-start;
    border: 1px solid var(--border-color);
    transition: transform 0.2s;
}
.info-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.info-icon {
    font-size: 36px;
}
.info-content {
    flex: 1;
}
.info-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.info-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.info-status {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 20px;
    display: inline-block;
}
.status-good {
    background: #d1fae5;
    color: #065f46;
}
.status-warning {
    background: #fef3c7;
    color: #92400e;
}
.feature-list {
    background: var(--bg-primary);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 30px;
    border: 1px solid var(--border-color);
}
.feature-list h3 {
    margin-bottom: 20px;
    font-size: 18px;
    color: var(--text-primary);
}
.feature-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.feature-tag {
    background: var(--bg-secondary);
    padding: 8px 16px;
    border-radius: 30px;
    font-size: 14px;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.update-log {
    background: var(--bg-primary);
    border-radius: 20px;
    padding: 24px;
    border: 1px solid var(--border-color);
}
.update-log h3 {
    margin-bottom: 20px;
    font-size: 18px;
    color: var(--text-primary);
}
.log-item {
    border-left: 3px solid var(--primary-color);
    padding-left: 20px;
    margin-bottom: 20px;
}
.log-item.featured {
    background: var(--primary-light);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
    border-left: 3px solid #f59e0b;
}
.log-version {
    font-weight: 600;
    font-size: 16px;
    color: var(--primary-color);
    margin-bottom: 4px;
}
.log-version .featured-badge {
    background: #f59e0b;
    color: white;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    margin-left: 10px;
}
.log-date {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.log-content ul {
    margin: 0;
    padding-left: 20px;
}
.log-content li {
    color: var(--text-secondary);
    margin: 6px 0;
    line-height: 1.5;
}
@media (max-width: 768px) {
    .version-card {
        padding: 24px;
    }
    .version-card h3 {
        font-size: 22px;
    }
    .info-grid {
        grid-template-columns: 1fr;
    }
    .info-item {
        padding: 16px;
    }
}
</style>