<?php
session_start();
include('../includes/config.php');

$bonus_ids = isset($_POST['bonus_ids']) ? $_POST['bonus_ids'] : array();

if (!empty($bonus_ids)) {
    $id_list = implode(',', array_map('intval', $bonus_ids));
    
    $sql = "SELECT COUNT(*) as count, SUM(amount) as total 
            FROM referral_transactions 
            WHERE id IN ($id_list) AND status = 'pending'";
    $result = mysqli_query($conn, $sql);
    $data = mysqli_fetch_assoc($result);
    
    echo json_encode(array(
        'success' => true,
        'count' => $data['count'] ?: 0,
        'total' => number_format($data['total'] ?: 0, 2)
    ));
} else {
    echo json_encode(array('success' => false));
}
?>