<?php require_once __DIR__ . '/../config.php'; require_admin(); $settings = get_settings(); ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Admin Control Room</title>
<link rel="stylesheet" href="../assets/css/style.css">
</head>
<body>
<div class="admin-shell">
  <aside class="admin-sidebar">
    <div class="brand">
      <img src="../assets/site-logo.png" alt="Logo">
      <div>
        <h2>Control Room</h2>
        <div class="meta">Broadcasturself Admin</div>
      </div>
    </div>
    <nav>
      <a href="index.php">Dashboard</a>
      <a href="site-control.php">Site Control</a>
      <a href="stations.php">Stations</a>
      <a href="schedule.php">Schedule</a>
      <a href="clues.php">Clues</a>
      <a href="answers.php">Answers</a>
      <a href="submissions.php">Submissions</a>
      <a href="dj-control.php">DJ Control</a>
      <a href="network.php">Network Sync</a>
      <a href="listeners.php">Listener Panel</a>
      <a href="poll.php">Poll Control</a>
      <a href="logout.php">Logout</a>
    </nav>
  </aside>
  <main class="admin-main">
    <?php
    $notice = '';
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_FILES['csv']['tmp_name'])) {
      $handle = fopen($_FILES['csv']['tmp_name'], 'r');
      $rows = [];
      if ($handle) {
        fgetcsv($handle);
        while (($row = fgetcsv($handle)) !== false) {
          $rows[] = [
            'name' => $row[0] ?? '',
            'email' => $row[1] ?? '',
            'platform' => $row[2] ?? '',
            'answer' => $row[3] ?? '',
            'details' => $row[4] ?? '',
            'correct' => (($row[5] ?? '') === 'Yes'),
            'is_winner' => (($row[6] ?? '') === 'Yes'),
            'timestamp' => $row[7] ?? '',
            'ip' => $row[8] ?? '',
          ];
        }
        fclose($handle);
        save_submissions($rows);
        $notice = 'CSV import complete.';
      }
    }
    ?>
    <div class="card">
      <h1>Import Submissions CSV</h1>
      <?php if ($notice): ?><div class="banner success"><?= esc($notice) ?></div><?php endif; ?>
      <form method="post" enctype="multipart/form-data">
        <label>CSV file</label>
        <input type="file" name="csv" accept=".csv" required>
        <div class="toolbar"><button type="submit">Upload CSV</button></div>
      </form>
    </div>

  </main>
</div>
</body>
</html>
