<?php
/**
 * 关于页面
 */
require_once __DIR__ . '/../includes/init.php';

$db = getDB();

// 获取"关于"页面内容
$stmt = $db->prepare("SELECT * FROM pages WHERE slug = 'about' AND status = 'published' LIMIT 1");
$stmt->execute();
$page = $stmt->fetch();

$title = $page['title'] ?? getSetting('about_title', '关于');
$content = $page['content_html'] ?? '';
if (empty($content) && !empty($page['content'])) {
    $content = parseMarkdown($page['content']);
}
if (empty($content)) {
    $content = '<p>' . nl2br(h(getSetting('about_content', '欢迎来到我的私人日记空间。'))) . '</p>';
}

// 获取一些统计
$postCount = (int)$db->query("SELECT COUNT(*) FROM posts WHERE status = 'published' AND is_public = 1")->fetchColumn();
$commentCount = (int)$db->query("SELECT COUNT(*) FROM comments WHERE status = 'approved'")->fetchColumn();
$tagCount = (int)$db->query("SELECT COUNT(*) FROM tags")->fetchColumn();

// 获取用户信息
$user = $db->query("SELECT * FROM users WHERE role = 'admin' ORDER BY id ASC LIMIT 1")->fetch();

$pageTitle = $title;
include ROOT_PATH . '/includes/header.php';
?>

<div class="about-section">
    <?php if (!empty($user['avatar'])): ?>
    <img class="about-avatar" src="<?php echo h($user['avatar']); ?>" alt="头像">
    <?php else: ?>
    <div class="about-avatar" style="background:rgba(255,110,64,0.15);display:inline-flex;align-items:center;justify-content:center;">
        <i class="mdui-icon material-icons" style="font-size:40px;color:#78909c;">person</i>
    </div>
    <?php endif; ?>

    <h1><?php echo h($title); ?></h1>

    <?php if (!empty($user['bio'])): ?>
    <p style="color:#78909c;font-size:13px;margin-top:8px;"><?php echo h($user['bio']); ?></p>
    <?php endif; ?>

    <!-- 统计 -->
    <div style="display:flex;justify-content:center;gap:24px;margin-top:20px;flex-wrap:wrap;">
        <div style="text-align:center;">
            <div style="font-size:22px;color:#cfd8dc;font-weight:300;"><?php echo $postCount; ?></div>
            <div style="font-size:11px;color:#546e7a;">日记</div>
        </div>
        <div style="text-align:center;">
            <div style="font-size:22px;color:#cfd8dc;font-weight:300;"><?php echo $commentCount; ?></div>
            <div style="font-size:11px;color:#546e7a;">留言</div>
        </div>
        <div style="text-align:center;">
            <div style="font-size:22px;color:#cfd8dc;font-weight:300;"><?php echo $tagCount; ?></div>
            <div style="font-size:11px;color:#546e7a;">标签</div>
        </div>
    </div>
</div>

<div class="about-content mdui-typo">
    <?php echo $content; ?>
</div>

<?php include ROOT_PATH . '/includes/footer.php'; ?>
