<?php
$alertsFile = "/var/www/html/alerts.json";
$alerts = [];

if (file_exists($alertsFile)) {
    $lines = file($alertsFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    $alerts = array_reverse($lines); // cele mai noi primele
}
?>
<html>
<head>
<meta http-equiv="refresh" content="30">
<style>
body { font-family: Arial, sans-serif; background: #f5f5f5; }
.alert { margin: 10px; padding: 10px; border-radius: 6px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.time { color: #555; font-size: 12px; }
.symbol { font-weight: bold; color: #0073e6; }
</style>
</head>
<body>
<h2>📊 Alerts Dashboard</h2>
<?php foreach($alerts as $line): 
  $data = json_decode($line, true); 
  if(!$data) continue; ?>
  <div class="alert">
    <div class="time"><?= htmlspecialchars($data["time"]) ?></div>
    <div><span class="symbol"><?= htmlspecialchars($data["symbol"]) ?></span> → <?= htmlspecialchars($data["alert"]) ?></div>
  </div>
<?php endforeach; ?>
</body>
</html>
