<?php
session_start();
require_once __DIR__ . '/auth/db.php';

header('Content-Type: application/json');

if (!isset($_SESSION['email'])) {
    echo json_encode(['count' => 0]);
    exit();
}

$email = $_SESSION['email'];

$stmt = $conn->prepare("SELECT COUNT(*) FROM users WHERE referred_by = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($count);
$stmt->fetch();
$stmt->close();

echo json_encode(['count' => $count]);
?>