<?php
session_start();
include '../db_config.php';
include '../functions.php';

// Check login/role if strictly needed, but might break if session not passed correctly in some envs
// For safety, let's keep it simple or check session.
if(!isset($_SESSION['role']) || $_SESSION['role'] != 'admin'){
    http_response_code(403);
    echo json_encode(['error' => 'Unauthorized']);
    exit;
}

$worker_count = $conn->query("SELECT COUNT(*) as count FROM employee_login WHERE role='employee'")->fetch_assoc()['count'];
$employer_count = $conn->query("SELECT COUNT(*) as count FROM employer_login WHERE role='employer'")->fetch_assoc()['count'];
$job_count = $conn->query("SELECT COUNT(*) as count FROM jobs")->fetch_assoc()['count'];
$pending_approvals = $conn->query("SELECT COUNT(*) as count FROM employee_details WHERE status='Pending'")->fetch_assoc()['count'];
$pending_employers = $conn->query("SELECT COUNT(*) as count FROM employer_details WHERE status='Pending'")->fetch_assoc()['count'];

header('Content-Type: application/json');
echo json_encode([
    'worker_count' => $worker_count,
    'employer_count' => $employer_count,
    'job_count' => $job_count,
    'job_count' => $job_count,
    'pending_approvals' => $pending_approvals,
    'pending_employers' => $pending_employers
]);
?>
