<?php
// devuelve todos los ítems del gasto + sus anexos
session_start();
require '../includes/session_control.php';
require_once __DIR__ . '/../cotizaciones/api/_node.php';

header('Content-Type: application/json; charset=utf-8');

$idGasto = intval($_GET['idGasto'] ?? 0);
if (!$idGasto) {
    echo json_encode([]);
    exit;
}

$token = cpn_node_token_or_fail();
$url = cpn_node_api_base() . '/api/gastos/anexos?idGasto=' . urlencode((string)$idGasto);
$resp = cpn_node_request('GET', $url, $token, null);

if (!($resp['ok'] ?? false)) {
    http_response_code(intval($resp['_http'] ?? 500));
    echo json_encode([]);
    exit;
}

echo json_encode($resp['data'] ?? []);
