<?php
$file = basename(__FILE__, '.php') . ".json";
$path = __DIR__ . "/" . $file;

if (!file_exists($path)) {
  http_response_code(404);
  echo "<h2>Le fichier JSON '$file' est introuvable.</h2>";
  exit;
}

$data = json_decode(file_get_contents($path), true);
if (!$data) {
  echo "<h2>Erreur : fichier JSON invalide ou vide.</h2>";
  exit;
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8" />
  <title><?php echo htmlspecialchars($data[0]['artist']); ?></title>
</head>
<body>
  <h1><?php echo htmlspecialchars($data[0]['artist']); ?></h1>
  <?php foreach ($data as $album): ?>
    <div>
      <h2><?php echo htmlspecialchars($album['title']); ?> (<?php echo $album['year']; ?>)</h2>
      <img src="<?php echo $album['cover']; ?>" width="200"><br>
      <strong>Genre:</strong> <?php echo htmlspecialchars($album['genre']); ?><br>
      <strong>Label:</strong> <?php echo htmlspecialchars($album['label']); ?><br>
      <pre><?php print_r($album['tracks']); ?></pre>
    </div><hr>
  <?php endforeach; ?>
</body>
</html>