<?php
if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
require_once __DIR__ . '/../includes/helpers.php';
require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/auth.php';

check_role('administrador');

// Set JSON response headers
header('Content-Type: application/json');
header('Cache-Control: no-cache, must-revalidate');

// Get dashboard data
$dashboard_data = RealTimeDashboard::get_dashboard_data();

// Get chart data
$charts = [
    'user_growth' => RealTimeDashboard::get_chart_data('user_growth', '24h'),
    'job_trends' => RealTimeDashboard::get_chart_data('job_trends', '24h'),
    'application_rates' => RealTimeDashboard::get_chart_data('application_rates', '24h'),
    'performance_trends' => RealTimeDashboard::get_chart_data('performance_trends', '7d')
];

echo json_encode([
    'success' => true,
    'metrics' => $dashboard_data,
    'charts' => $charts,
    'timestamp' => time()
]);
?>