<?php
// public/api/debug_func.php
require_once '../../config.php';
require_once '../../functions.php';

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

$response = [];

try {
    // Test Admin
    $response['admin_groups'] = get_active_contact_groups('admin');
    $response['admin_groups_count'] = count($response['admin_groups']);

    // Test User (Try with session if available, or force ID 1 for testing)
    $user_id = $_SESSION['user_id'] ?? 1;
    $response['test_user_id'] = $user_id;
    $response['user_groups'] = get_active_contact_groups('user', $user_id);
    $response['user_groups_count'] = count($response['user_groups']);

} catch (Exception $e) {
    $response['error'] = $e->getMessage();
}

echo json_encode($response, JSON_PRETTY_PRINT);
