<?php
require_once __DIR__ . '/../config/db.php';
if (session_status() === PHP_SESSION_NONE) session_start();
if (!isset($_SESSION['admin_id'])) { header('Location: /WATCHING/admin/login.php'); exit; }

$res = db()->query("SELECT id, title, is_featured FROM products ORDER BY title ASC");
if (isset($_GET['id'])) {
  $id = (int)$_GET['id'];
  db()->query("UPDATE products SET is_featured = 1 - is_featured WHERE id = $id");
  header('Location: /WATCHING/admin/featured.php'); exit;
}
?>
<!doctype html>
<html><head><link href="/WATCHING/assets/css/styles.css" rel="stylesheet"></head><body class="glass-bg">
<div class="container glass-card" style="padding:16px;margin-top:20px;">
  <h2>Featured Products</h2>
  <table class="table">
    <thead><tr><th>Title</th><th>Featured</th><th>Toggle</th></tr></thead>
    <tbody>
      <?php while ($p = $res->fetch_assoc()): ?>
        <tr>
          <td><?php echo htmlspecialchars($p['title']); ?></td>
          <td><?php echo $p['is_featured'] ? 'Yes' : 'No'; ?></td>
          <td><a class="btn" href="?id=<?php echo $p['id']; ?>">Toggle</a></td>
        </tr>
      <?php endwhile; ?>
    </tbody>
  </table>
</div>
</body></html>