<?php
require_once '../config/config.php';

$page_name = '控制面板';
$active_page = 'dashboard';

// 获取统计数据
$conn = db_connect();
$categories_count = $conn->query("SELECT COUNT(*) as count FROM categories")->fetch_assoc()['count'];
$links_count = $conn->query("SELECT COUNT(*) as count FROM links")->fetch_assoc()['count'];
$conn->close();

include 'includes/header.php';
?>

<div class="container-fluid">
    <!-- 统计卡片 -->
    <div class="row">
        <div class="col-md-6 mb-4">
            <div class="card h-100">
                <div class="card-body">
                    <h5 class="card-title text-muted mb-4">分类总数</h5>
                    <h2 class="display-4 mb-1"><?php echo $categories_count; ?></h2>
                    <a href="category.php" class="btn btn-primary mt-3">管理分类</a>
                </div>
            </div>
        </div>
        <div class="col-md-6 mb-4">
            <div class="card h-100">
                <div class="card-body">
                    <h5 class="card-title text-muted mb-4">链接总数</h5>
                    <h2 class="display-4 mb-1"><?php echo $links_count; ?></h2>
                    <a href="link.php" class="btn btn-primary mt-3">管理链接</a>
                </div>
            </div>
        </div>
    </div>

    <!-- 快捷操作 -->
    <div class="card">
        <div class="card-header">
            <h5 class="card-title mb-0">快捷操作</h5>
        </div>
        <div class="card-body">
            <div class="row g-3">
                <div class="col-md-3">
                    <a href="category.php?action=add" class="btn btn-primary w-100">添加分类</a>
                </div>
                <div class="col-md-3">
                    <a href="link.php?action=add" class="btn btn-success w-100">添加链接</a>
                </div>
                <div class="col-md-3">
                    <a href="settings.php" class="btn btn-info w-100">网站设置</a>
                </div>
                <div class="col-md-3">
                    <a href="../" target="_blank" class="btn btn-secondary w-100">查看网站</a>
                </div>
            </div>
        </div>
    </div>

    <?php include 'includes/footer.php'; ?>
</div>
