<?php
require_once __DIR__ . "/../auth/require-auth.php";
require_once __DIR__ . "/../services/db.php";

$taskId = $_GET["task"];

$sql = "SELECT a.*, u.name AS user_name
        FROM activity_log a
        LEFT JOIN users u ON a.user_id = u.id
        WHERE a.task_id = ?
        ORDER BY a.created_at DESC";
$stmt = sqlsrv_query($conn, $sql, [$taskId]);

$items = [];
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    $items[] = $row;
}

echo json_encode($items);
