<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Poll Results | Almost Heaven Radio</title>
  <link rel="stylesheet" href="../css/style.css" />
</head>
<body>
  <?php include('../header.php'); ?>
  <?php include('../menu.php'); ?>

  <main class="main-container">
    <section class="schedule-preview">
      <h2 class="text-warning">Current Poll & Results</h2>

      <?php
        $poll_file = '../data/poll.json';
        $votes_file = '../data/poll_votes.json';

        $poll = file_exists($poll_file) ? json_decode(file_get_contents($poll_file), true) : null;
        $votes = file_exists($votes_file) ? json_decode(file_get_contents($votes_file), true) : [];
        if (!is_array($poll)) $poll = null;
        if (!is_array($votes)) $votes = [];
      ?>

      <?php if ($poll && !empty($poll['question']) && !empty($poll['options'])): ?>
        <div class="dj-slot now">
          <p><strong>Question:</strong> <?= htmlspecialchars($poll['question']) ?></p>
          <ul class="poll-results">
            <?php foreach ((array)$poll['options'] as $i => $option): $count = (int)($votes[$option] ?? $votes[$i] ?? 0); ?>
              <li><?= htmlspecialchars($option) ?> — <strong><?= $count ?> vote<?= $count !== 1 ? 's' : '' ?></strong></li>
            <?php endforeach; ?>
          </ul>
        </div>
      <?php else: ?>
        <div class="dj-slot coming">
          <p>No poll data available.</p>
        </div>
      <?php endif; ?>
    </section>
  </main>

  <?php include('../footer.php'); ?>
</body>
</html>
