<?php
$cookieJar = tempnam(sys_get_temp_dir(), 'zzcookie10');
$base = 'http://localhost:8080/traderalign';
$uid = '278d5983-d646-494f-a130-b22f7c321867';

$ch = curl_init("{$base}/public/_zz_test_autologin.php?uid=" . urlencode($uid));
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEJAR => $cookieJar, CURLOPT_COOKIEFILE => $cookieJar]);
curl_exec($ch);
curl_close($ch);

$accountId = '03f94727-2811-48a2-bb79-3325c4d3de2a';
$url = "{$base}/trading-center?hub=accounts&kind=prop&view=center&challenge=three_step&stage=funded&account_id=" . urlencode($accountId);
$ch = curl_init($url);
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEJAR => $cookieJar, CURLOPT_COOKIEFILE => $cookieJar]);
$resp = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
@unlink($cookieJar);

echo "HTTP {$code}\n";
$hasError = (stripos($resp, 'Warning:') !== false || stripos($resp, 'Fatal error') !== false || stripos($resp, 'Notice:') !== false || stripos($resp, 'Deprecated:') !== false || stripos($resp, 'Parse error') !== false);
echo 'PHP error: ' . ($hasError ? 'YES !!!' : 'no') . "\n";

if (preg_match('/Current Balance<\/span><span>\$([\d,\.]+)/', $resp, $m)) {
    echo "Rendered Current Balance: \${$m[1]}\n";
    echo ($m[1] === '5,250.00') ? "PASS — shows the correct phase-aware balance, not the buggy \$9,468.62 whole-ledger sum.\n" : "!!! UNEXPECTED VALUE\n";
} else {
    echo "Current Balance row not found in output.\n";
    echo substr($resp, 0, 500) . "\n";
}
