<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/include_all.inc.php';

if (isset($_GET['group_id'])) {
    $stmt = $pdo->prepare("
        SELECT h.*, u.user_email as changed_by_email 
        FROM wp_pro_status_history h
        LEFT JOIN wp_users u ON h.changed_by = u.ID
        WHERE h.group_id = ?
        ORDER BY h.changed_at DESC
    ");
    $stmt->execute([$_GET['group_id']]);
    $history = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo json_encode(['success' => true, 'history' => $history]);
}