<?php
require_once __DIR__ . '/includes/header.php';

// Estatísticas do sistema
$total_urls = (int)db()->query("SELECT COUNT(*) FROM app_urls WHERE is_active = 1")->fetchColumn();
$total_users = (int)db()->query("SELECT COUNT(*) FROM app_users WHERE is_active = 1")->fetchColumn();

$branding = get_branding();
$notes = get_notes();
$settings = get_general_settings();

// Tema atual
$theme_config = get_user_theme($user_id);
$current_theme_mode = $theme_config['mode'];
$available_themes = get_available_themes();

// Nome do tema atual
if ($current_theme_mode === 'custom') {
    $theme_display = '🎨 CSS Personalizado';
} else {
    $theme_display = $available_themes[$current_theme_mode]['icon'] . ' ' . $available_themes[$current_theme_mode]['name'];
}
?>

<style>
    .dashboard-header {
        margin-bottom: 30px;
    }
    
    .dashboard-header h1 {
        font-size: 28px;
        margin-bottom: 8px;
        background: var(--primary-bg);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    .dashboard-header p {
        color: #999;
        font-size: 14px;
    }
    
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 20px;
        margin-bottom: 30px;
    }
    
    .stat-card {
        background: #1a1a1a;
        padding: 25px;
        border-radius: 10px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        transition: all 0.3s ease;
    }
    
    .stat-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
        border-color: rgba(255, 255, 255, 0.2);
    }
    
    .stat-card h3 {
        font-size: 14px;
        color: #999;
        margin-bottom: 10px;
        text-transform: uppercase;
        letter-spacing: 1px;
    }
    
    .stat-card .value {
        font-size: 36px;
        font-weight: bold;
        background: var(--primary-bg);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    .info-section {
        background: #1a1a1a;
        padding: 25px;
        border-radius: 10px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        margin-bottom: 20px;
    }
    
    .info-section h2 {
        font-size: 18px;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        background: var(--primary-bg);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    .info-row {
        display: flex;
        justify-content: space-between;
        padding: 12px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }
    
    .info-row:last-child {
        border-bottom: none;
    }
    
    .info-row label {
        color: #999;
        font-size: 14px;
    }
    
    .info-row value {
        color: #fff;
        font-weight: 500;
    }
    
    .quick-actions {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 15px;
        margin-top: 30px;
    }
    
    .action-btn {
        display: block;
        padding: 15px 20px;
        background: var(--link-bg);
        color: #fff;
        text-decoration: none;
        border-radius: 8px;
        text-align: center;
        transition: all 0.2s ease;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .action-btn:hover {
        background: var(--primary-bg);
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    }
    
    @media (max-width: 768px) {
        .dashboard-header h1 {
            font-size: 24px;
        }
        
        .stats-grid {
            grid-template-columns: 1fr;
        }
        
        .quick-actions {
            grid-template-columns: 1fr;
        }
    }
</style>

<div class="dashboard-header">
    <h1>📊 Dashboard</h1>
    <p>Bem-vindo ao painel administrativo, <?php echo htmlspecialchars($username); ?>!</p>
</div>

<div class="stats-grid">
    <div class="stat-card">
        <h3>URLs Ativas</h3>
        <div class="value"><?php echo $total_urls; ?></div>
    </div>
    
    <div class="stat-card">
        <h3>Usuários Ativos</h3>
        <div class="value"><?php echo $total_users; ?></div>
    </div>
    
    <div class="stat-card">
        <h3>Tema Ativo</h3>
        <div class="value" style="font-size: 20px;">
            <?php echo $theme_display; ?>
        </div>
    </div>
</div>



<h2 style="margin: 30px 0 15px; font-size: 18px;">🚀 Ações Rápidas</h2>
<div class="quick-actions">
    <a href="dns.php" class="action-btn">✅ Ativar Cliente</a>
    <a href="support.php" class="action-btn">📲 QR Suporte</a>
    <a href="background.php" class="action-btn">🖼️ Trocar Background</a>
    <a href="logo.php" class="action-btn">🏷️ Trocar Logo</a>
    <a href="perfil.php" class="action-btn">⚙️ Meu Perfil</a>
</div>

</main>
</body>
</html>
